Browse Source

Fix blockquote termination by list item

close https://github.com/markdown-it/markdown-it/issues/338
pull/343/head
Alex Kocharin 7 years ago
parent
commit
c57f593b23
  1. 6
      CHANGELOG.md
  2. 38
      lib/rules_block/blockquote.js
  3. 3
      lib/rules_block/fence.js
  4. 3
      lib/rules_block/heading.js
  5. 3
      lib/rules_block/hr.js
  6. 3
      lib/rules_block/html_block.js
  7. 3
      lib/rules_block/lheading.js
  8. 3
      lib/rules_block/list.js
  9. 3
      lib/rules_block/reference.js
  10. 43
      test/fixtures/markdown-it/commonmark_extras.txt

6
CHANGELOG.md

@ -1,3 +1,9 @@
8.3.1 / WIP
------------------
- Fix blockquote termination by list item, #338.
8.3.0 / 2017-02-16
------------------

38
lib/rules_block/blockquote.js

@ -10,6 +10,7 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
ch,
i,
initial,
isOutdented,
l,
lastLineEmpty,
lines,
@ -25,9 +26,13 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
terminate,
terminatorRules,
token,
oldLineMax = state.lineMax,
pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine];
// if it's indented more than 3 spaces, it should be a code block
if (state.sCount[startLine] - state.blkIndent >= 4) { return false; }
// check the block quote marker
if (state.src.charCodeAt(pos++) !== 0x3E/* > */) { return false; }
@ -35,9 +40,6 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
// so no point trying to find the end of it in silent mode
if (silent) { return true; }
oldIndent = state.blkIndent;
state.blkIndent = 0;
// skip spaces after ">" and re-calculate offset
initial = offset = state.sCount[startLine] + pos - (state.bMarks[startLine] + state.tShift[startLine]);
@ -118,13 +120,21 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
// >
// test
// ```
// 3. another tag
// 3. another tag:
// ```
// > test
// - - -
// ```
for (nextLine = startLine + 1; nextLine < endLine; nextLine++) {
if (state.sCount[nextLine] < oldIndent) { break; }
// check if it's outdented, i.e. it's inside list item and indented
// less than said list item:
//
// ```
// 1. anything
// > current blockquote
// 2. checking this line
// ```
isOutdented = state.sCount[nextLine] < state.blkIndent;
pos = state.bMarks[nextLine] + state.tShift[nextLine];
max = state.eMarks[nextLine];
@ -134,7 +144,7 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
break;
}
if (state.src.charCodeAt(pos++) === 0x3E/* > */) {
if (state.src.charCodeAt(pos++) === 0x3E/* > */ && !isOutdented) {
// This line is inside the blockquote.
// skip spaces after ">" and re-calculate offset
@ -214,7 +224,13 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
}
if (terminate) {
if (oldIndent !== 0) {
// Quirk to enforce "hard termination mode" for paragraphs;
// normally if you call `tokenize(state, startLine, nextLine)`,
// paragraphs will look below nextLine for paragraph continuation,
// but if blockquote is terminated by another tag, they shouldn't
state.lineMax = nextLine;
if (state.blkIndent !== 0) {
// state.blkIndent was non-zero, we now set it to zero,
// so we need to re-calculate all offsets to appear as
// if indent wasn't changed
@ -222,12 +238,14 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
oldBSCount.push(state.bsCount[nextLine]);
oldTShift.push(state.tShift[nextLine]);
oldSCount.push(state.sCount[nextLine]);
state.sCount[nextLine] -= oldIndent;
state.sCount[nextLine] -= state.blkIndent;
}
break;
}
if (isOutdented) break;
oldBMarks.push(state.bMarks[nextLine]);
oldBSCount.push(state.bsCount[nextLine]);
oldTShift.push(state.tShift[nextLine]);
@ -238,6 +256,9 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
state.sCount[nextLine] = -1;
}
oldIndent = state.blkIndent;
state.blkIndent = 0;
token = state.push('blockquote_open', 'blockquote', 1);
token.markup = '>';
token.map = lines = [ startLine, 0 ];
@ -247,6 +268,7 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
token = state.push('blockquote_close', 'blockquote', -1);
token.markup = '>';
state.lineMax = oldLineMax;
state.parentType = oldParentType;
lines[1] = state.line;

3
lib/rules_block/fence.js

@ -9,6 +9,9 @@ module.exports = function fence(state, startLine, endLine, silent) {
pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine];
// if it's indented more than 3 spaces, it should be a code block
if (state.sCount[startLine] - state.blkIndent >= 4) { return false; }
if (pos + 3 > max) { return false; }
marker = state.src.charCodeAt(pos);

3
lib/rules_block/heading.js

@ -10,6 +10,9 @@ module.exports = function heading(state, startLine, endLine, silent) {
pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine];
// if it's indented more than 3 spaces, it should be a code block
if (state.sCount[startLine] - state.blkIndent >= 4) { return false; }
ch = state.src.charCodeAt(pos);
if (ch !== 0x23/* # */ || pos >= max) { return false; }

3
lib/rules_block/hr.js

@ -10,6 +10,9 @@ module.exports = function hr(state, startLine, endLine, silent) {
pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine];
// if it's indented more than 3 spaces, it should be a code block
if (state.sCount[startLine] - state.blkIndent >= 4) { return false; }
marker = state.src.charCodeAt(pos++);
// Check hr marker

3
lib/rules_block/html_block.js

@ -25,6 +25,9 @@ module.exports = function html_block(state, startLine, endLine, silent) {
pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine];
// if it's indented more than 3 spaces, it should be a code block
if (state.sCount[startLine] - state.blkIndent >= 4) { return false; }
if (!state.md.options.html) { return false; }
if (state.src.charCodeAt(pos) !== 0x3C/* < */) { return false; }

3
lib/rules_block/lheading.js

@ -8,6 +8,9 @@ module.exports = function lheading(state, startLine, endLine/*, silent*/) {
nextLine = startLine + 1, oldParentType,
terminatorRules = state.md.block.ruler.getRules('paragraph');
// if it's indented more than 3 spaces, it should be a code block
if (state.sCount[startLine] - state.blkIndent >= 4) { return false; }
oldParentType = state.parentType;
state.parentType = 'paragraph'; // use paragraph to match terminatorRules

3
lib/rules_block/list.js

@ -129,6 +129,9 @@ module.exports = function list(state, startLine, endLine, silent) {
isTerminatingParagraph = false,
tight = true;
// if it's indented more than 3 spaces, it should be a code block
if (state.sCount[startLine] - state.blkIndent >= 4) { return false; }
// limit conditions when list can interrupt
// a paragraph (validation mode only)
if (silent && state.parentType === 'paragraph') {

3
lib/rules_block/reference.js

@ -27,6 +27,9 @@ module.exports = function reference(state, startLine, _endLine, silent) {
max = state.eMarks[startLine],
nextLine = startLine + 1;
// if it's indented more than 3 spaces, it should be a code block
if (state.sCount[startLine] - state.blkIndent >= 4) { return false; }
if (state.src.charCodeAt(pos) !== 0x5B/* [ */) { return false; }
// Simple check to quickly interrupt scan on [link](url) at the start of line.

43
test/fixtures/markdown-it/commonmark_extras.txt

@ -202,6 +202,22 @@ foo2<br>
bar</p>
.
List item terminating quote should not be paragraph continuation
.
1. foo
> quote
2. bar
.
<ol>
<li>foo
<blockquote>
<p>quote</p>
</blockquote>
</li>
<li>bar</li>
</ol>
.
Coverage. Directive can terminate paragraph.
.
a
@ -441,3 +457,30 @@ Coverage. Tabs in lists.
</li>
</ol>
.
Coverage. Various tags not interrupting blockquotes because of indentation:
.
> foo
- - - -
> foo
# not a heading
> foo
```
not a fence
```
.
<blockquote>
<p>foo
- - - -</p>
</blockquote>
<blockquote>
<p>foo
# not a heading</p>
</blockquote>
<blockquote>
<p>foo
<code>not a fence</code></p>
</blockquote>
.

Loading…
Cancel
Save