Skip to content

Commit b64076f

Browse files
committed
Merge branch 'main' into fix-integrations-error
2 parents 143b9ed + af98402 commit b64076f

File tree

7 files changed

+49
-13
lines changed

7 files changed

+49
-13
lines changed

.changeset/curly-rules-learn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": minor
3+
---
4+
5+
Add support for inline icons.

bun.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@
285285
"react-dom": "^19.0.0",
286286
},
287287
"catalog": {
288-
"@gitbook/api": "^0.120.0",
288+
"@gitbook/api": "^0.121.0",
289289
},
290290
"packages": {
291291
"@ai-sdk/provider": ["@ai-sdk/[email protected]", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-0M+qjp+clUD0R1E5eWQFhxEvWLNaOtGQRUaBn8CUABnSKredagq92hUS9VjOzGsTm37xLfpaxl97AVtbeOsHew=="],
@@ -650,7 +650,7 @@
650650

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

653-
"@gitbook/api": ["@gitbook/api@0.120.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-FiRmPiSBwobMxmNjd14QkkOdM95BAPLDDRShgpS9Vsd8lHjNMyZfrJKVJTsJUuFcgYoi4cqNw9yu/TiUBUgv3g=="],
653+
"@gitbook/api": ["@gitbook/api@0.121.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-o4/N24RM0Rg8S/3yPDjPmt6TbQF+1iZmg9q9QKxOxMqpQ2bZmMUqS7dSkeqEbEBMALx/m/x0xQlJbEJGbOwteg=="],
654654

655655
"@gitbook/cache-do": ["@gitbook/cache-do@workspace:packages/cache-do"],
656656

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"workspaces": {
3737
"packages": ["packages/*"],
3838
"catalog": {
39-
"@gitbook/api": "^0.120.0"
39+
"@gitbook/api": "^0.121.0"
4040
}
4141
},
4242
"patchedDependencies": {

packages/gitbook/e2e/internal.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,11 @@ const testCases: TestsCase[] = [
603603
url: 'blocks/emojis',
604604
run: waitForCookiesDialog,
605605
},
606+
{
607+
name: 'Icons',
608+
url: 'blocks/icons',
609+
run: waitForCookiesDialog,
610+
},
606611
{
607612
name: 'Links',
608613
url: 'blocks/links',

packages/gitbook/src/components/DocumentView/CodeBlock/highlight.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript';
1313
import { type BundledLanguage, bundledLanguages } from 'shiki/langs';
1414

15+
import { nullIfNever } from '@/lib/typescript';
1516
import { plainHighlight } from './plain-highlight';
1617

1718
export type HighlightLine = {
@@ -263,16 +264,28 @@ function getPlainCodeBlockLine(
263264
if (node.object === 'text') {
264265
content += cleanupLine(node.leaves.map((leaf) => leaf.text).join(''));
265266
} else {
266-
const start = index + content.length;
267-
content += getPlainCodeBlockLine(node, index + content.length, inlines);
268-
const end = index + content.length;
269-
270-
if (inlines) {
271-
inlines.push({
272-
inline: node,
273-
start,
274-
end,
275-
});
267+
switch (node.type) {
268+
case 'annotation': {
269+
const start = index + content.length;
270+
content += getPlainCodeBlockLine(node, index + content.length, inlines);
271+
const end = index + content.length;
272+
273+
if (inlines) {
274+
inlines.push({
275+
inline: node,
276+
start,
277+
end,
278+
});
279+
}
280+
break;
281+
}
282+
case 'expression': {
283+
break;
284+
}
285+
default: {
286+
nullIfNever(node);
287+
break;
288+
}
276289
}
277290
}
278291
}

packages/gitbook/src/components/DocumentView/Inline.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Annotation } from './Annotation/Annotation';
55
import type { DocumentContextProps } from './DocumentView';
66
import { Emoji } from './Emoji';
77
import { InlineButton } from './InlineButton';
8+
import { InlineIcon } from './InlineIcon';
89
import { InlineImage } from './InlineImage';
910
import { InlineLink } from './InlineLink';
1011
import { InlineMath } from './Math';
@@ -47,6 +48,8 @@ export function Inline<T extends DocumentInline>(props: InlineProps<T>) {
4748
return <InlineImage {...contextProps} inline={inline} />;
4849
case 'button':
4950
return <InlineButton {...contextProps} inline={inline} />;
51+
case 'icon':
52+
return <InlineIcon {...contextProps} inline={inline} />;
5053
case 'expression':
5154
// The GitBook API should take care of evaluating expressions.
5255
// We should never need to render them.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { DocumentInlineIcon } from '@gitbook/api';
2+
3+
import { Icon, type IconName } from '@gitbook/icons';
4+
import type { InlineProps } from './Inline';
5+
6+
export async function InlineIcon(props: InlineProps<DocumentInlineIcon>) {
7+
const { inline } = props;
8+
9+
return <Icon icon={inline.data.icon as IconName} className="inline size-[1em]" />;
10+
}

0 commit comments

Comments
 (0)