Skip to content

Commit ca21733

Browse files
wooormSamyPesse
andcommitted
Fix escaping phrasing characters in table cell
Closes GH-1. Co-authored-by: Samy Pessé <samypesse@gmail.com>
1 parent 91a2d89 commit ca21733

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,12 @@ export function gfmTableToMarkdown(options) {
161161
*/
162162
function handleTableCell(node, _, context) {
163163
const exit = context.enter('tableCell')
164+
const subexit = context.enter('phrasing')
164165
const value = containerPhrasing(node, context, {
165166
before: around,
166167
after: around
167168
})
169+
subexit()
168170
exit()
169171
return value
170172
}

test.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,18 +318,14 @@ test('mdast -> markdown', (t) => {
318318
children: [
319319
{type: 'tableCell', children: [{type: 'text', value: 'a'}]},
320320
{type: 'tableCell', children: [{type: 'text', value: '古'}]},
321-
{
322-
type: 'tableCell',
323-
children: [{type: 'text', value: '\u001B[1m古\u001B[22m'}]
324-
},
325321
{type: 'tableCell', children: [{type: 'text', value: '🤔'}]}
326322
]
327323
}
328324
]
329325
},
330326
{extensions: [gfmTableToMarkdown({stringLength: stringWidth})]}
331327
),
332-
'| a | 古 | \u001B[1m古\u001B[22m | 🤔 |\n| - | -- | -- | -- |\n',
328+
'| a | 古 | 🤔 |\n| - | -- | -- |\n',
333329
'should support `stringLength`'
334330
)
335331

@@ -414,6 +410,22 @@ test('mdast -> markdown', (t) => {
414410
'should escape eols in a table cell'
415411
)
416412

413+
t.deepEqual(
414+
toMarkdown(
415+
{
416+
type: 'tableRow',
417+
children: [
418+
{type: 'tableCell', children: [{type: 'text', value: '<a>'}]},
419+
{type: 'tableCell', children: [{type: 'text', value: '*a'}]},
420+
{type: 'tableCell', children: [{type: 'text', value: '![]()'}]}
421+
]
422+
},
423+
{extensions: [gfmTableToMarkdown()]}
424+
),
425+
'| \\<a> | \\*a | !\\[]\\() |\n',
426+
'should escape phrasing characters in table cells'
427+
)
428+
417429
t.deepEqual(
418430
toMarkdown(
419431
{type: 'tableCell', children: [{type: 'text', value: 'a|b'}]},

0 commit comments

Comments
 (0)