Skip to content

Commit 168a4fa

Browse files
authored
Add support for buttons to GitBook. (#3117)
1 parent 3ea75ad commit 168a4fa

File tree

6 files changed

+64
-16
lines changed

6 files changed

+64
-16
lines changed

Diff for: .changeset/lucky-elephants-hang.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
Add support for buttons to GitBook.

Diff for: bun.lock

+14-14
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
"name": "@gitbook/icons",
166166
"version": "0.2.0",
167167
"bin": {
168-
"gitbook-icons": "./bin/gitbook-icons.js",
168+
"gitbook-icons": "./bin/gitbook-icons.js"
169169
},
170170
"dependencies": {
171171
"@fortawesome/fontawesome-free": "^6.6.0",
@@ -222,7 +222,7 @@
222222
"name": "@gitbook/react-math",
223223
"version": "0.6.0",
224224
"bin": {
225-
"gitbook-math": "./bin/gitbook-math.js",
225+
"gitbook-math": "./bin/gitbook-math.js"
226226
},
227227
"dependencies": {
228228
"object-hash": "^3.0.0",
@@ -265,7 +265,7 @@
265265
},
266266
"overrides": {
267267
"@codemirror/state": "6.4.1",
268-
"@gitbook/api": "0.108.0",
268+
"@gitbook/api": "0.109.0",
269269
"react": "18.3.1",
270270
"react-dom": "18.3.1",
271271
},
@@ -626,7 +626,7 @@
626626

627627
"@fortawesome/fontawesome-svg-core": ["@fortawesome/[email protected]", "", { "dependencies": { "@fortawesome/fontawesome-common-types": "6.6.0" } }, "sha512-KHwPkCk6oRT4HADE7smhfsKudt9N/9lm6EJ5BVg0tD1yPA5hht837fB87F8pn15D8JfTqQOjhKTktwmLMiD7Kg=="],
628628

629-
"@gitbook/api": ["@gitbook/api@0.108.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-OytauuT3IMf0zl6rBvIacQ7YphzNhpuNAvEVQbysCGo3BhGYD1xv+vXVmtkAGUnFEAclw2fg2VjWPt3sOlQsAg=="],
629+
"@gitbook/api": ["@gitbook/api@0.109.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-nzhxmiNR2MMHh+HoU7fFdOJ+u4BFyXjtsVquQf3VhZMjeI71yeLx5JEbjkOcijVd/GMAtvpYlYR2qcPqzq27gw=="],
630630

631631
"@gitbook/cache-do": ["@gitbook/cache-do@workspace:packages/cache-do"],
632632

@@ -4022,7 +4022,7 @@
40224022

40234023
"gaxios/node-fetch": ["[email protected]", "", { "dependencies": { "whatwg-url": "^5.0.0" }, "peerDependencies": { "encoding": "^0.1.0" }, "optionalPeers": ["encoding"] }, "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A=="],
40244024

4025-
"gitbook-v2/next": ["[email protected]", "", { "dependencies": { "@next/env": "15.3.0-canary.37", "@swc/counter": "0.1.3", "@swc/helpers": "0.5.15", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001579", "postcss": "8.4.31", "styled-jsx": "5.1.6" }, "optionalDependencies": { "@next/swc-darwin-arm64": "15.3.0-canary.37", "@next/swc-darwin-x64": "15.3.0-canary.37", "@next/swc-linux-arm64-gnu": "15.3.0-canary.37", "@next/swc-linux-arm64-musl": "15.3.0-canary.37", "@next/swc-linux-x64-gnu": "15.3.0-canary.37", "@next/swc-linux-x64-musl": "15.3.0-canary.37", "@next/swc-win32-arm64-msvc": "15.3.0-canary.37", "@next/swc-win32-x64-msvc": "15.3.0-canary.37", "sharp": "^0.33.5" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", "@playwright/test": "^1.41.2", "babel-plugin-react-compiler": "*", "react": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "react-dom": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "sass": "^1.3.0" }, "optionalPeers": ["@opentelemetry/api", "@playwright/test", "babel-plugin-react-compiler", "sass"], "bin": { "next": "dist/bin/next" } }, "sha512-K9BJZoFYnp+WqR7jYSCzrBJHOwTXJOED964z0En7qszrjF2HXfa24W2bFAMBwK56JD+h4lUyhpbgBoDiDN+vnA=="],
4025+
"gitbook-v2/next": ["[email protected]", "", { "dependencies": { "@next/env": "15.3.0-canary.42", "@swc/counter": "0.1.3", "@swc/helpers": "0.5.15", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001579", "postcss": "8.4.31", "styled-jsx": "5.1.6" }, "optionalDependencies": { "@next/swc-darwin-arm64": "15.3.0-canary.42", "@next/swc-darwin-x64": "15.3.0-canary.42", "@next/swc-linux-arm64-gnu": "15.3.0-canary.42", "@next/swc-linux-arm64-musl": "15.3.0-canary.42", "@next/swc-linux-x64-gnu": "15.3.0-canary.42", "@next/swc-linux-x64-musl": "15.3.0-canary.42", "@next/swc-win32-arm64-msvc": "15.3.0-canary.42", "@next/swc-win32-x64-msvc": "15.3.0-canary.42", "sharp": "^0.33.5" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", "@playwright/test": "^1.41.2", "babel-plugin-react-compiler": "*", "react": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "react-dom": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "sass": "^1.3.0" }, "optionalPeers": ["@opentelemetry/api", "@playwright/test", "babel-plugin-react-compiler", "sass"], "bin": { "next": "dist/bin/next" } }, "sha512-f1KQC+GOE72/MYvxEedYY+jpZch3pzNrz51euqt87xWGiRlIngO2VQEbFDwQHZwvzkOtKmC1lDd2Clkd5sLsTQ=="],
40264026

40274027
"global-dirs/ini": ["[email protected]", "", {}, "sha512-iKpRpXP+CrP2jyrxvg1kMUpXDyRUFDWurxbnVT1vQPx+Wz9uCYsMIqYuSBLV+PAaZG/d7kRLKRFc9oDMsH+mFQ=="],
40284028

@@ -4890,23 +4890,23 @@
48904890

48914891
"gaxios/https-proxy-agent/debug": ["[email protected]", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ=="],
48924892

4893-
"gitbook-v2/next/@next/env": ["@next/[email protected].37", "", {}, "sha512-NoG8pEk34zpIphk7vSTZ6zs3rj33jtxWO5E2o+bCE8gjFQunChNnRWP1OPo2cATmnc64aJKcvdX5uOuEtAvoUw=="],
4893+
"gitbook-v2/next/@next/env": ["@next/[email protected].42", "", {}, "sha512-J/lYYosUhRJwLejxEkdXoc8NOhJKzMA/aUTQaXD1qGzMWDkvQ5FisO336WMKHRMIVXf1yu2G4JMKOZJ50Qhq+w=="],
48944894

4895-
"gitbook-v2/next/@next/swc-darwin-arm64": ["@next/[email protected].37", "", { "os": "darwin", "cpu": "arm64" }, "sha512-H+gorYP1jSJCmPDpTlQIyLS6GXkA6WZ74H7lxHeXWdAWyP7zv/MmxuhPmsD/RFzYEwZNDSk9jVFpYcOvfWK1Hw=="],
4895+
"gitbook-v2/next/@next/swc-darwin-arm64": ["@next/[email protected].42", "", { "os": "darwin", "cpu": "arm64" }, "sha512-9RlirdgHKaoI97IfVqXlRxhZNuqK9IuWdEu5xZ7fLphYKF+HKAMuqIO1/z53Bl4CSRM7DDpRiyXAyqDJ4VBr7g=="],
48964896

4897-
"gitbook-v2/next/@next/swc-darwin-x64": ["@next/[email protected].37", "", { "os": "darwin", "cpu": "x64" }, "sha512-zul0GsE7SGga8DdBWHRYzdQC5WST1RMmVJRxutvqCqcm7R/GosIzibrEFE5AkW7XMh6bZCO71r4zKPehTuWFcg=="],
4897+
"gitbook-v2/next/@next/swc-darwin-x64": ["@next/[email protected].42", "", { "os": "darwin", "cpu": "x64" }, "sha512-ZAUP4zGtED0mzFYZprch/Pqz3UCnOAee/IdHsKl7uVlmnUyX43I6dDDmk1Srae5RlLu1pVdUkT2tJfT1JKo06w=="],
48984898

4899-
"gitbook-v2/next/@next/swc-linux-arm64-gnu": ["@next/[email protected].37", "", { "os": "linux", "cpu": "arm64" }, "sha512-ucAOG0sMG2MkNbGTFAI0qncbkci0VE34xjwcpxUT7LUv/rWG83oVOcxcGY5xVbz9V6MpPCxr62FV3I5h6t+w0w=="],
4899+
"gitbook-v2/next/@next/swc-linux-arm64-gnu": ["@next/[email protected].42", "", { "os": "linux", "cpu": "arm64" }, "sha512-ttgFELQ0oebZNDQweq0jh7ixk8kfUeC6xr3qzjF0eqQygy+DuhEjAzDYZsfCi6G1ToRXJ8+spkZS7Lhv6GNMqw=="],
49004900

4901-
"gitbook-v2/next/@next/swc-linux-arm64-musl": ["@next/[email protected].37", "", { "os": "linux", "cpu": "arm64" }, "sha512-hVnST5YroTumu1y+UB4HXN2mbmTs5VWqsr8KmQonAc7+Uu9hvjSb79cpCD5B97h0TBb34Z2vr90hN9w0Q06PFA=="],
4901+
"gitbook-v2/next/@next/swc-linux-arm64-musl": ["@next/[email protected].42", "", { "os": "linux", "cpu": "arm64" }, "sha512-XVhtQ6RMbnQMxrm0nWJ5lOrr/48U+Gv8A5mOFwh1URiq9Ur1QBHIzdYJRUFyoN3n0+qSplOyqCzhff3YRauNRQ=="],
49024902

4903-
"gitbook-v2/next/@next/swc-linux-x64-gnu": ["@next/[email protected].37", "", { "os": "linux", "cpu": "x64" }, "sha512-p7ArUaiTRm5pSqHg60UtJbZUzsOU90idibVRPgnXd+0Kec7n6TClE3pWcIFow9by0bpSi6kmbNmkHf61i0Kerw=="],
4903+
"gitbook-v2/next/@next/swc-linux-x64-gnu": ["@next/[email protected].42", "", { "os": "linux", "cpu": "x64" }, "sha512-ycfjoWE9vxUsZc6LW27aiqiq0m7OtjVz4Ptd9gW5ya8YJvhSWK/0kXo9CVadIFMlX4xJpKl194bZZCJrbD3pvA=="],
49044904

4905-
"gitbook-v2/next/@next/swc-linux-x64-musl": ["@next/[email protected].37", "", { "os": "linux", "cpu": "x64" }, "sha512-Egi3swoN3pbseJ3oRGFYs94ICEjmzmY+exWfNlpycjBMWp1m/QzIcIxHTdz2/Lqe5SNGVMrJ8uEDNAD2knqgvw=="],
4905+
"gitbook-v2/next/@next/swc-linux-x64-musl": ["@next/[email protected].42", "", { "os": "linux", "cpu": "x64" }, "sha512-jr5CIZ6C1QJg2AJQY/vCELLR0EH1DyL+cRfPTDHC5lt2vI3AFsUO6n3rmN0rtOZuMQG4zH3ZrRgMHcZaX5aaDQ=="],
49064906

4907-
"gitbook-v2/next/@next/swc-win32-arm64-msvc": ["@next/[email protected].37", "", { "os": "win32", "cpu": "arm64" }, "sha512-gOE0lBeS/ztrSHnXimEp9D5OOTN86moSfMgC05ei/UJSFyT7YEZa4FRYRDzctNEilRJC2DBnxjEpeD+JhDuf6A=="],
4907+
"gitbook-v2/next/@next/swc-win32-arm64-msvc": ["@next/[email protected].42", "", { "os": "win32", "cpu": "arm64" }, "sha512-0Qfe9yKHExdVDQd5NKpGvWYGB0Uz45r4OvxjpOyy5QMZ5j/wzg1BhgM2EfoXoEiBrzeEXnZ2MTk14GwS+BzQLQ=="],
49084908

4909-
"gitbook-v2/next/@next/swc-win32-x64-msvc": ["@next/[email protected].37", "", { "os": "win32", "cpu": "x64" }, "sha512-J/SjJYN1Nj/olRC0ykfDNKKoxJss4a3Zf340UeyHbmbqeKHvGbT/H0QFMx+3DT+Sqar3PqbyZBLbxpE/QYct1w=="],
4909+
"gitbook-v2/next/@next/swc-win32-x64-msvc": ["@next/[email protected].42", "", { "os": "win32", "cpu": "x64" }, "sha512-SJ5Qj+2duEuwILQLAXH12J74XqJMiulC/VC5+f64FurqC34ESVsgtgzZQAfhkDmp8B/8D24wgL0LTivsVO1vbw=="],
49104910

49114911
"gitbook-v2/next/postcss": ["[email protected]", "", { "dependencies": { "nanoid": "^3.3.6", "picocolors": "^1.0.0", "source-map-js": "^1.0.2" } }, "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ=="],
49124912

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@codemirror/state": "6.4.1",
1313
"react": "18.3.1",
1414
"react-dom": "18.3.1",
15-
"@gitbook/api": "0.108.0"
15+
"@gitbook/api": "0.109.0"
1616
},
1717
"private": true,
1818
"scripts": {

Diff for: packages/gitbook/src/components/DocumentView/Inline.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type {
22
DocumentInline,
33
DocumentInlineAnnotation,
4+
DocumentInlineButton,
45
DocumentInlineEmoji,
56
DocumentInlineImage,
67
DocumentInlineLink,
@@ -13,6 +14,7 @@ import assertNever from 'assert-never';
1314
import { Annotation } from './Annotation/Annotation';
1415
import type { DocumentContextProps } from './DocumentView';
1516
import { Emoji } from './Emoji';
17+
import { InlineButton } from './InlineButton';
1618
import { InlineImage } from './InlineImage';
1719
import { InlineLink } from './InlineLink';
1820
import { InlineMath } from './Math';
@@ -44,7 +46,8 @@ export function Inline<
4446
| DocumentInlineEmoji
4547
| DocumentInlineLink
4648
| DocumentInlineMath
47-
| DocumentInlineMention,
49+
| DocumentInlineMention
50+
| DocumentInlineButton,
4851
>(props: InlineProps<T>) {
4952
const { inline, ...contextProps } = props;
5053

@@ -61,6 +64,8 @@ export function Inline<
6164
return <Mention {...contextProps} inline={inline} />;
6265
case 'inline-image':
6366
return <InlineImage {...contextProps} inline={inline} />;
67+
case 'button':
68+
return <InlineButton {...contextProps} inline={inline} />;
6469
default:
6570
assertNever(inline);
6671
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { resolveContentRef } from '@/lib/references';
2+
import * as api from '@gitbook/api';
3+
import { Button } from '../primitives';
4+
import type { InlineProps } from './Inline';
5+
6+
export async function InlineButton(props: InlineProps<api.DocumentInlineButton>) {
7+
const { inline, context } = props;
8+
9+
if (!context.contentContext) {
10+
throw new Error('InlineButton requires a contentContext');
11+
}
12+
13+
const resolved = await resolveContentRef(inline.data.ref, context.contentContext);
14+
15+
if (!resolved) {
16+
return null;
17+
}
18+
19+
return (
20+
<Button
21+
href={resolved.href}
22+
label={inline.data.label}
23+
// TODO: use a variant specifically for user-defined buttons.
24+
variant={inline.data.kind}
25+
insights={{
26+
type: 'link_click',
27+
link: {
28+
target: inline.data.ref,
29+
position: api.SiteInsightsLinkPosition.Content,
30+
},
31+
}}
32+
/>
33+
);
34+
}

Diff for: packages/gitbook/src/components/DocumentView/Text.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ const MARK_STYLES = {
4747
strikethrough: Strikethrough,
4848
color: Color,
4949
keyboard: Keyboard,
50+
51+
// TODO: add support for these marks
52+
subscript: null,
53+
superscript: null,
5054
};
5155

5256
interface MarkedLeafProps<Mark extends DocumentTextMark> {

0 commit comments

Comments
 (0)