Skip to content

Commit 07054ca

Browse files
committed
Fix number sign at end of heading (atx)
Closes GH-20.
1 parent 51db1f9 commit 07054ca

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/unsafe.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module.exports = [
3636
{character: '"', inConstruct: 'titleQuote'},
3737
// A number sign could start an ATX heading if it starts a line.
3838
{atBreak: true, character: '#'},
39+
{character: '#', inConstruct: 'headingAtx', after: '(?:[\r\n]|$)'},
3940
// Dollar sign and percentage are not used in markdown.
4041
// An ampersand could start a character reference.
4142
{character: '&', after: '[#A-Za-z]', inConstruct: 'phrasing'},

test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,24 @@ test('heading', function (t) {
10781078
'should not escape a `>` at the start of phrasing in a heading'
10791079
)
10801080

1081+
t.equal(
1082+
to({type: 'heading', children: [{type: 'text', value: 'a #'}]}),
1083+
'# a \\#\n',
1084+
'should escape a `#` at the end of a heading (1)'
1085+
)
1086+
1087+
t.equal(
1088+
to({type: 'heading', children: [{type: 'text', value: 'a ##'}]}),
1089+
'# a #\\#\n',
1090+
'should escape a `#` at the end of a heading (2)'
1091+
)
1092+
1093+
t.equal(
1094+
to({type: 'heading', children: [{type: 'text', value: 'a # b'}]}),
1095+
'# a # b\n',
1096+
'should not escape a `#` in a heading (2)'
1097+
)
1098+
10811099
t.end()
10821100
})
10831101

0 commit comments

Comments
 (0)