fix(editor): match fence suffix whitespace rules

This commit is contained in:
Neil
2026-09-18 23:40:19 -07:00
parent 8157e9e148
commit 482b03cc45
2 changed files with 11 additions and 8 deletions
@@ -10,17 +10,20 @@ export type MarkdownFenceTracker = {
// Top-level fence delimiters may be indented by at most three spaces.
const FENCE_LINE = /[ ]{0,3}(`{3,}|~{3,})/y
function hasClosingSuffix(content: string, start: number, end: number): boolean {
let sawWhitespace = false
for (let index = start; index < end; index += 1) {
const character = content.charCodeAt(index)
if (
character !== 126 &&
character !== 96 &&
character !== 32 &&
character !== 9 &&
character !== 13
) {
if (character === 32 || character === 9 || character === 13) {
sawWhitespace = true
continue
}
if ((character === 126 || character === 96) && !sawWhitespace) {
continue
}
if (character !== 126 && character !== 96) {
return false
}
return false
}
return true
}
@@ -34,7 +34,7 @@ it.each(['\n', '\r\n', '\r'])('retains %j terminators while stripping code', (eo
)
})
it.each(['```~~~', ' ```'])('matches the parser on the closer %j', (closer) => {
it.each(['```~~~', '``` ~', ' ```'])('matches the parser on the closer %j', (closer) => {
const source = `\`\`\`\ncode\n${closer}\n<div>after</div>\n`
const code = marked.lexer(source)[0]
expect(code.type).toBe('code')