mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 00:02:31 +00:00
fix(editor): match parser fence whitespace
This commit is contained in:
@@ -13,16 +13,13 @@ 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 === 32 || character === 9 || character === 13) {
|
||||
if (character === 32) {
|
||||
sawWhitespace = true
|
||||
continue
|
||||
}
|
||||
if ((character === 126 || character === 96) && !sawWhitespace) {
|
||||
continue
|
||||
}
|
||||
if (character !== 126 && character !== 96) {
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -34,13 +34,16 @@ it.each(['\n', '\r\n', '\r'])('retains %j terminators while stripping code', (eo
|
||||
)
|
||||
})
|
||||
|
||||
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')
|
||||
expect(getMarkdownFenceRanges(source)).toEqual([[0, code.raw.length]])
|
||||
expect(stripMarkdownCode(source).includes('<div>after</div>')).toBe(closer === '```~~~')
|
||||
})
|
||||
it.each(['```~~~', '``` ~', '```\t', ' ```'])(
|
||||
'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')
|
||||
expect(getMarkdownFenceRanges(source)).toEqual([[0, code.raw.length]])
|
||||
expect(stripMarkdownCode(source).includes('<div>after</div>')).toBe(closer === '```~~~')
|
||||
}
|
||||
)
|
||||
|
||||
it.each(['-', '--', '---'])('keeps multiline spans after a bare %s line', (divider) => {
|
||||
const source = `Text\n${divider}\nA \`code\nspan\` here`
|
||||
|
||||
Reference in New Issue
Block a user