Skip to content

Commit 50392b7

Browse files
committed
Fix escaping multiple pipes in code in table cell
Closes remarkjs/remark#583.
1 parent 25473a5 commit 50392b7

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,5 +400,40 @@ test('mdast -> markdown', function (t) {
400400
'should escape pipes in a table cell'
401401
)
402402

403+
t.deepEqual(
404+
toMarkdown(
405+
{type: 'tableCell', children: [{type: 'inlineCode', value: 'a|b|c'}]},
406+
{extensions: [table.toMarkdown()]}
407+
),
408+
'`a\\|b\\|c`\n',
409+
'should escape multiple pipes in inline code in a table cell'
410+
)
411+
412+
t.deepEqual(
413+
toMarkdown(
414+
{type: 'tableCell', children: [{type: 'text', value: 'a|b|c'}]},
415+
{extensions: [table.toMarkdown()]}
416+
),
417+
'a\\|b\\|c\n',
418+
'should escape multiple pipes in a table cell'
419+
)
420+
421+
t.deepEqual(
422+
toMarkdown(
423+
{type: 'tableCell', children: [{type: 'inlineCode', value: 'a||b'}]},
424+
{extensions: [table.toMarkdown()]}
425+
),
426+
'`a\\|\\|b`\n',
427+
'should escape adjacent pipes in inline code in a table cell'
428+
)
429+
t.deepEqual(
430+
toMarkdown(
431+
{type: 'tableCell', children: [{type: 'text', value: 'a||b'}]},
432+
{extensions: [table.toMarkdown()]}
433+
),
434+
'a\\|\\|b\n',
435+
'should escape adjacent pipes in a table cell'
436+
)
437+
403438
t.end()
404439
})

to-markdown.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function toMarkdown(options) {
104104
var value = defaultInlineCode(node, parent, context)
105105

106106
if (context.stack.indexOf('tableCell') !== -1) {
107-
value = value.replace(/\|/, '\\$&')
107+
value = value.replace(/\|/g, '\\$&')
108108
}
109109

110110
return value

0 commit comments

Comments
 (0)