Skip to content

Commit 65c7c55

Browse files
committed
fix?
1 parent d38eb79 commit 65c7c55

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

src/utils/markdown/plugins/collectHeadings.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ export type MarkdownHeading = {
1010
level: number
1111
}
1212

13-
export function rehypeCollectHeadings(headings: MarkdownHeading[]) {
13+
export function rehypeCollectHeadings(initialHeadings?: MarkdownHeading[]) {
14+
const headings = initialHeadings ?? []
15+
1416
return function collectHeadings(tree: Root, file: any) {
1517
visit(tree, 'element', (node) => {
1618
if (!isHeading(node)) {

src/utils/markdown/plugins/syntaxHighlight.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,16 @@ export const rehypeShikiHighlight = () => {
9494
}
9595
}
9696

97-
const htmlFragments = await Promise.all(
98-
DEFAULT_THEMES.map((theme) =>
99-
highlighter.codeToHtml(codeText, {
100-
lang: effectiveLang,
101-
theme,
102-
transformers: [transformerNotationDiff()],
103-
}),
104-
),
105-
)
106-
10797
node.tagName = 'div'
98+
const existingClasses = Array.isArray(node.properties?.className)
99+
? (node.properties?.className as string[])
100+
: typeof node.properties?.className === 'string'
101+
? String(node.properties.className).split('\n')
102+
: []
103+
108104
node.properties = {
109105
...node.properties,
110-
className: [
111-
...(Array.isArray(node.properties?.className)
112-
? (node.properties?.className as string[])
113-
: []),
114-
'shiki-wrapper',
115-
],
106+
className: [...existingClasses, 'shiki-wrapper'],
116107
'data-language': normalizedLang,
117108
}
118109

@@ -126,6 +117,16 @@ export const rehypeShikiHighlight = () => {
126117
return
127118
}
128119

120+
const htmlFragments = await Promise.all(
121+
DEFAULT_THEMES.map((theme) =>
122+
highlighter.codeToHtml(codeText, {
123+
lang: effectiveLang,
124+
theme,
125+
transformers: [transformerNotationDiff()],
126+
}),
127+
),
128+
)
129+
129130
const fragmentTrees = htmlFragments.map((fragment) =>
130131
fragmentParser.parse(fragment) as Root,
131132
)

src/utils/markdown/processor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function renderMarkdown(content): MarkdownRenderResult {
7171
className: ['anchor-heading'],
7272
},
7373
})
74-
.use((node, file) => rehypeCollectHeadings(node, file, headings))
74+
.use(rehypeCollectHeadings(headings))
7575

7676
const file = processor.use(rehypeStringify).processSync(content)
7777

0 commit comments

Comments
 (0)