Skip to content

Commit d4ceea9

Browse files
committed
Fix to encode { in markdown
1 parent 52243a9 commit d4ceea9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,5 +285,23 @@ test('mdast -> markdown', function (t) {
285285
'should serialize text expressions'
286286
)
287287

288+
t.deepEqual(
289+
toMarkdown(
290+
{type: 'paragraph', children: [{type: 'text', value: 'a { b'}]},
291+
{extensions: [mdxExpression.toMarkdown]}
292+
),
293+
'a \\{ b\n',
294+
'should escape `{` in text'
295+
)
296+
297+
t.deepEqual(
298+
toMarkdown(
299+
{type: 'definition', url: 'x', title: 'a\n{\nb'},
300+
{extensions: [mdxExpression.toMarkdown]}
301+
),
302+
'[]: x "a\n\\{\nb"\n',
303+
'should escape `{` at the start of a line'
304+
)
305+
288306
t.end()
289307
})

to-markdown.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ exports.handlers = {
33
mdxTextExpression: handleMdxExpression
44
}
55

6+
exports.unsafe = [
7+
{character: '{', inConstruct: ['phrasing']},
8+
{atBreak: true, character: '{'}
9+
]
10+
611
var eol = /\r?\n|\r/g
712

813
function handleMdxExpression(node) {

0 commit comments

Comments
 (0)