Skip to content

Commit 8f62a86

Browse files
committed
chore: update vue-renderer-markdown to version 0.0.56-beta.2 and enhance math delimiter handling in tests
1 parent efb0696 commit 8f62a86

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

pnpm-lock.yaml

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

src/utils/markdown/plugins/math.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ export function applyMath(md: MarkdownIt, mathOpts?: MathOptions) {
221221
}
222222
const delimiters: [string, string][] = [
223223
['$$', '$$'],
224+
['\\(', '\\)'],
224225
['\(', '\)'],
225226
]
226227
let searchPos = 0
@@ -280,7 +281,6 @@ export function applyMath(md: MarkdownIt, mathOpts?: MathOptions) {
280281
searchPos = index + open.length
281282
continue
282283
}
283-
284284
const content = src.slice(index + open.length, endIdx)
285285

286286
foundAny = true
@@ -369,6 +369,7 @@ export function applyMath(md: MarkdownIt, mathOpts?: MathOptions) {
369369
silent: boolean,
370370
) => {
371371
const delimiters: [string, string][] = [
372+
['\\[', '\\]'],
372373
['\[', '\]'],
373374
['$$', '$$'],
374375
]

test/findMatchingClose.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ describe('findMatchingClose', () => {
1212
expect(src.slice(found, found + 2)).toBe('\\)')
1313
})
1414

15+
it('finds matching close for nested parentheses with escaped braces -1', () => {
16+
const src = '"总之,\\(\\boldsymbol{\\alpha}^T \\boldsymbol{\\beta} = 0\\)"'
17+
18+
// search for the open after the leading '\\('
19+
const openIdx = src.indexOf('\\(')
20+
// start looking after the opener
21+
const found = findMatchingClose(src, openIdx + 2, '\\(', '\\)')
22+
console.log({ found, openIdx })
23+
expect(found).toBeGreaterThan(openIdx)
24+
expect(src.slice(found, found + 2)).toBe('\\)')
25+
})
26+
1527
it('finds matching close for $$ delimiter', () => {
1628
const src = '$$ E = mc^2 $$ and more'
1729
const openIdx = src.indexOf('$$')

0 commit comments

Comments
 (0)