Skip to content

Commit 8ef4035

Browse files
committed
chore: upgrade minimark
1 parent 9b6df0c commit 8ef4035

6 files changed

Lines changed: 23 additions & 26 deletions

File tree

SPEC/MDC/shiki-codeblock-highlight-complex.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
timeout:
3-
parse: 100ms
3+
parse: 150ms
44
html: 5ms
55
markdown: 5ms
66
options:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"markdown-it": "^14.1.0",
4242
"markdown-it-mdc": "^0.2.8",
4343
"markdown-it-sub": "^2.0.0",
44-
"minimark": "https://pkg.pr.new/minimark@9df41a4",
44+
"minimark": "https://pkg.pr.new/minimark@bf0f08a",
4545
"nuxt": "^4.3.0",
4646
"obuild": "^0.4.22",
4747
"remark-gfm": "^4.0.1",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/stream.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,10 @@ export async function* parseStreamIncremental(
163163

164164
// Auto-close unclosed syntax before parsing intermediate results
165165
const closedContent = autoCloseMarkdown(accumulatedContent)
166-
// console.log({closedContent})
167166

168167
// Parse the auto-closed content
169168
const result = parse(closedContent, options)
170-
// console.log({result})
169+
171170
yield {
172171
chunk: chunkStr,
173172
body: result.body,

src/utils/shiki-highlighter.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface ShikiOptions {
2424

2525
let highlighter: Highlighter | null = null
2626
let highlighterPromise: Promise<Highlighter> | null = null
27-
let loadedThemes: Set<string> = new Set()
27+
const loadedThemes: Set<string> = new Set()
2828

2929
/**
3030
* Get or create the Shiki highlighter instance
@@ -107,44 +107,42 @@ export async function highlightCode(
107107

108108
// Use codeToTokens to get raw tokens
109109
const result = hl.codeToTokens(code, {
110-
lang: language,
110+
lang: language as BundledLanguage,
111111
theme: theme as BundledTheme | string,
112112
})
113113

114-
console.log(result.tokens)
115114
// Build minimark nodes from tokens (flatten all lines)
116115
const allTokens: MinimarkNode[] = []
117-
116+
118117
for (let i = 0; i < result.tokens.length; i++) {
119118
const lineTokens = result.tokens[i]
120119

121120
const lineTokensNodes: MinimarkNode[] = []
122121
for (const token of lineTokens) {
123122
const style = colorToStyle(token.color)
124-
123+
125124
// Create a span with style for colored tokens
126125
// Note: we always wrap in spans if there's a style, even for whitespace
127126
// because the whitespace may be part of the styled token
128127
if (style) {
129128
lineTokensNodes.push(['span', { style }, token.content] as MinimarkNode)
130-
} else {
129+
}
130+
else {
131131
// Plain text token (no style)
132132
lineTokensNodes.push(token.content)
133133
}
134134
}
135135

136-
137136
allTokens.push(['span', { class: 'line' }, ...lineTokensNodes])
138137

139138
// Add newline between lines (except for last line)
140139
if (i < result.tokens.length - 1) {
141140
allTokens.push('\n')
142141
}
143-
144142
}
145143

146-
return {
147-
nodes: allTokens,
144+
return {
145+
nodes: allTokens,
148146
language,
149147
bgColor: result.bg,
150148
fgColor: result.fg,
@@ -176,29 +174,29 @@ export async function highlightCodeBlocks(
176174

177175
// Check if this is a pre > code structure
178176
if (Array.isArray(node) && node[0] === 'pre') {
179-
const [tag, attrs, ...children] = node
177+
const [_tag, attrs, ...children] = node
180178

181179
// Look for code element as child
182180
if (children.length > 0 && Array.isArray(children[0]) && children[0][0] === 'code') {
183181
const codeNode = children[0]
184182
const [, codeAttrs, content] = codeNode
185183

186184
// Extract language from attributes
187-
const language = (attrs as any)?.language ||
188-
((codeAttrs as any)?.class as string)?.replace('language-', '') ||
189-
'text'
185+
const language = (attrs as any)?.language
186+
|| ((codeAttrs as any)?.class as string)?.replace('language-', '')
187+
|| 'text'
190188

191189
if (typeof content === 'string') {
192190
try {
193191
const { nodes, bgColor, fgColor } = await highlightCode(content, language, options)
194192

195193
// Build pre attributes with Shiki styling
196-
const newPreAttrs: any = {
194+
const newPreAttrs: any = {
197195
...attrs,
198196
class: `shiki ${options.theme || 'github-dark'}`,
199197
tabindex: '0',
200198
}
201-
199+
202200
if (bgColor || fgColor) {
203201
const styles: string[] = []
204202
if (bgColor) styles.push(`background-color:${bgColor}`)

test/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function extractFrontmatter(content: string): { timeouts?: TestCase['timeouts'],
4747
return {
4848
timeouts: Object.keys(timeouts).length > 0 ? timeouts : undefined,
4949
options: data.options as TestCase['options'] | undefined,
50-
body
50+
body,
5151
}
5252
}
5353

0 commit comments

Comments
 (0)