Skip to content

Commit c599879

Browse files
authored
Merge pull request #420 from nobkd/fix-nuemark/code-block-escapes
fix(glow): escaping line start
2 parents e1a75f3 + f720c66 commit c599879

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

packages/glow/src/glow.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ export function renderRow(row, lang, mark=true) {
213213
ret.push(row.substring(index))
214214
const res = ret.join('')
215215

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

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

249249
// escape character
250-
if (!prefix && c == '\\') line = line.slice(1)
250+
if (prefix && c == '\\') line = line.slice(1)
251251

252252
html.push({ line, wrap })
253253
}

packages/glow/test/glow.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ test('disable mark', () => {
4747
expect(html).toInclude('• girl')
4848
})
4949

50+
test('escape prefixes', () => {
51+
const blocks = parseSyntax([
52+
'\\+ not really adding a line',
53+
'\\- not really removing a line',
54+
'\\| not really marking a line'
55+
], 'md')
56+
57+
expect(blocks[0].line).toEqual('+ not really adding a line')
58+
expect(blocks[1].line).toEqual('- not really removing a line')
59+
expect(blocks[2].line).toEqual('| not really marking a line')
60+
})
61+
5062
test('disable prefixes', () => {
5163
const blocks = parseSyntax([
5264
'+ not really adding a line',

0 commit comments

Comments
 (0)