Skip to content

Commit 9d6af62

Browse files
committed
Fix closing paren followed by punctuation
Closes remarkjs/remark-gfm#12.
1 parent 0b0a67f commit 9d6af62

2 files changed

Lines changed: 62 additions & 22 deletions

File tree

syntax.js

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ var www = {tokenize: tokenizeWww, partial: true}
99
var domain = {tokenize: tokenizeDomain, partial: true}
1010
var path = {tokenize: tokenizePath, partial: true}
1111
var punctuation = {tokenize: tokenizePunctuation, partial: true}
12-
var paren = {tokenize: tokenizeParen, partial: true}
1312
var namedCharacterReference = {
1413
tokenize: tokenizeNamedCharacterReference,
1514
partial: true
@@ -410,7 +409,11 @@ function tokenizePath(effects, ok) {
410409

411410
// `)`
412411
if (code === 41) {
413-
return effects.check(paren, parenAtPathEnd, continuedPunctuation)(code)
412+
return effects.check(
413+
punctuation,
414+
parenAtPathEnd,
415+
continuedPunctuation
416+
)(code)
414417
}
415418

416419
if (pathEnd(code)) {
@@ -467,26 +470,6 @@ function tokenizeNamedCharacterReference(effects, ok, nok) {
467470
}
468471
}
469472

470-
function tokenizeParen(effects, ok, nok) {
471-
return start
472-
473-
function start(code) {
474-
// Assume a right paren.
475-
effects.consume(code)
476-
return after
477-
}
478-
479-
function after(code) {
480-
// If the punctuation marker is followed by the end of the path, it’s not
481-
// continued punctuation.
482-
return pathEnd(code) ||
483-
// `)`
484-
code === 41
485-
? ok(code)
486-
: nok(code)
487-
}
488-
}
489-
490473
function tokenizePunctuation(effects, ok, nok) {
491474
return start
492475

test/index.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,62 @@ test('markdown -> html (micromark)', function (t) {
110110
'should support named character references in domains'
111111
)
112112

113+
t.deepEqual(
114+
micromark('https://a.bc/d/e/).', {
115+
extensions: [syntax],
116+
htmlExtensions: [html]
117+
}),
118+
'<p><a href="https://a.bc/d/e/">https://a.bc/d/e/</a>).</p>',
119+
'should support a closing paren and period after a path'
120+
)
121+
122+
t.deepEqual(
123+
micromark('https://a.bc/d/e/.)', {
124+
extensions: [syntax],
125+
htmlExtensions: [html]
126+
}),
127+
'<p><a href="https://a.bc/d/e/">https://a.bc/d/e/</a>.)</p>',
128+
'should support a period and closing paren after a path'
129+
)
130+
131+
t.deepEqual(
132+
micromark('https://a.bc).', {extensions: [syntax], htmlExtensions: [html]}),
133+
'<p><a href="https://a.bc">https://a.bc</a>).</p>',
134+
'should support a closing paren and period after a domain'
135+
)
136+
137+
t.deepEqual(
138+
micromark('https://a.bc.)', {extensions: [syntax], htmlExtensions: [html]}),
139+
'<p><a href="https://a.bc">https://a.bc</a>.)</p>',
140+
'should support a period and closing paren after a domain'
141+
)
142+
143+
t.deepEqual(
144+
micromark('https://a.bc).d', {
145+
extensions: [syntax],
146+
htmlExtensions: [html]
147+
}),
148+
'<p><a href="https://a.bc).d">https://a.bc).d</a></p>',
149+
'should support a closing paren and period in a path'
150+
)
151+
152+
t.deepEqual(
153+
micromark('https://a.bc.)d', {
154+
extensions: [syntax],
155+
htmlExtensions: [html]
156+
}),
157+
'<p><a href="https://a.bc.)d">https://a.bc.)d</a></p>',
158+
'should support a period and closing paren in a path'
159+
)
160+
161+
t.deepEqual(
162+
micromark('https://a.bc/))d', {
163+
extensions: [syntax],
164+
htmlExtensions: [html]
165+
}),
166+
'<p><a href="https://a.bc/))d">https://a.bc/))d</a></p>',
167+
'should support two closing parens in a path'
168+
)
169+
113170
t.end()
114171
})

0 commit comments

Comments
 (0)