Skip to content

Commit

Permalink
Merge pull request #420 from nobkd/fix-nuemark/code-block-escapes
Browse files Browse the repository at this point in the history
fix(glow): escaping line start
  • Loading branch information
tipiirai authored Dec 13, 2024
2 parents e1a75f3 + f720c66 commit c599879
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/glow/src/glow.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ export function renderRow(row, lang, mark=true) {
ret.push(row.substring(index))
const res = ret.join('')

return !mark ? res : res.replace(MARK, (_, a, b, c) => {
return elem(a[1] ? 'u' : 'mark', b)
return !mark ? res : res.replace(MARK, (_, marker, content) => {
return elem(marker[1] ? 'u' : 'mark', content)
})
}

Expand Down Expand Up @@ -247,7 +247,7 @@ export function parseSyntax(lines, lang, prefix = true) {
if (wrap) line = (line[1] == ' ' ? ' ' : '') + line.slice(1)

// escape character
if (!prefix && c == '\\') line = line.slice(1)
if (prefix && c == '\\') line = line.slice(1)

html.push({ line, wrap })
}
Expand Down
12 changes: 12 additions & 0 deletions packages/glow/test/glow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ test('disable mark', () => {
expect(html).toInclude('• girl')
})

test('escape prefixes', () => {
const blocks = parseSyntax([
'\\+ not really adding a line',
'\\- not really removing a line',
'\\| not really marking a line'
], 'md')

expect(blocks[0].line).toEqual('+ not really adding a line')
expect(blocks[1].line).toEqual('- not really removing a line')
expect(blocks[2].line).toEqual('| not really marking a line')
})

test('disable prefixes', () => {
const blocks = parseSyntax([
'+ not really adding a line',
Expand Down

0 comments on commit c599879

Please sign in to comment.