Browse Source

Fix reference edge-case

pull/135/head
Alex Kocharin 10 years ago
parent
commit
02c04be9e5
  1. 11
      lib/rules_block/reference.js
  2. 16
      test/fixtures/commonmark/bad.txt
  3. 10
      test/fixtures/commonmark/good.txt

11
lib/rules_block/reference.js

@ -144,6 +144,17 @@ module.exports = function reference(state, startLine, _endLine, silent) {
// skip trailing spaces until the rest of the line
while (pos < max && str.charCodeAt(pos) === 0x20/* space */) { pos++; }
if (pos < max && str.charCodeAt(pos) !== 0x0A) {
if (title) {
// garbage at the end of the line after title,
// but it could still be a valid reference if we roll back
title = '';
pos = destEndPos;
lines = destEndLineNo;
while (pos < max && str.charCodeAt(pos) === 0x20/* space */) { pos++; }
}
}
if (pos < max && str.charCodeAt(pos) !== 0x0A) {
// garbage at the end of the line
return false;

16
test/fixtures/commonmark/bad.txt

@ -67,22 +67,6 @@ error:
</blockquote>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 2479
.
[foo]: /url
"title" ok
.
<p>&quot;title&quot; ok</p>
.
error:
<p>[foo]: /url
&quot;title&quot; ok</p>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 4737

10
test/fixtures/commonmark/good.txt

@ -2062,6 +2062,16 @@ src line: 2471
<p>[foo]: /url &quot;title&quot; ok</p>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 2479
.
[foo]: /url
"title" ok
.
<p>&quot;title&quot; ok</p>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 2489

Loading…
Cancel
Save