|
|
@ -3,13 +3,12 @@ |
|
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
|
|
var skipSpaces = require('../helpers').skipSpaces; |
|
|
|
var getLines = require('../helpers').getLines; |
|
|
|
var getLines = require('../helpers').getLines; |
|
|
|
var isEmpty = require('../helpers').isEmpty; |
|
|
|
|
|
|
|
|
|
|
|
module.exports = function blockquote(state, startLine, endLine, silent) { |
|
|
|
var nextLine, lastLineEmpty, subState, |
|
|
|
rules_named = state.lexerBlock.rules_named, |
|
|
|
var nextLine, subState, insideLines, lineMax, |
|
|
|
pos = state.bMarks[startLine] + state.tShift[startLine], |
|
|
|
max = state.eMarks[startLine]; |
|
|
|
|
|
|
@ -25,63 +24,37 @@ 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; } |
|
|
|
|
|
|
|
// check if we have an empty blockquote
|
|
|
|
pos = pos < max ? skipSpaces(state, pos) : pos; |
|
|
|
lastLineEmpty = pos >= max; |
|
|
|
|
|
|
|
// Search the end of the block
|
|
|
|
//
|
|
|
|
// Block ends with either:
|
|
|
|
// 1. an empty line outside:
|
|
|
|
// ```
|
|
|
|
// > test
|
|
|
|
//
|
|
|
|
// ```
|
|
|
|
// 2. an empty line inside:
|
|
|
|
// ```
|
|
|
|
// >
|
|
|
|
// test
|
|
|
|
// ```
|
|
|
|
// 3. another tag
|
|
|
|
// ```
|
|
|
|
// > test
|
|
|
|
// - - -
|
|
|
|
// ```
|
|
|
|
for (nextLine = startLine + 1; nextLine < endLine; nextLine++) { |
|
|
|
lineMax = state.lineMax; |
|
|
|
insideLines = 1; |
|
|
|
state.tokens.push({ type: 'blockquote_open' }); |
|
|
|
for (nextLine = startLine + 1; nextLine < lineMax; ) { |
|
|
|
pos = state.bMarks[nextLine] + state.tShift[nextLine]; |
|
|
|
max = state.eMarks[nextLine]; |
|
|
|
|
|
|
|
if (pos >= max) { |
|
|
|
// Case 1: line is not inside the blockquote, and this line is empty.
|
|
|
|
break; |
|
|
|
if (pos < max && state.src.charCodeAt(pos++) === 0x3E/* > */) { |
|
|
|
if (nextLine < endLine) { |
|
|
|
nextLine++; |
|
|
|
insideLines++; |
|
|
|
continue; |
|
|
|
} else { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (state.src.charCodeAt(pos++) === 0x3E/* > */) { |
|
|
|
// This line is inside the blockquote.
|
|
|
|
pos = pos < max ? skipSpaces(state, pos) : pos; |
|
|
|
lastLineEmpty = pos >= max; |
|
|
|
continue; |
|
|
|
if (insideLines === 0) { |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// Case 2: line is not inside the blockquote, and the last line was empty.
|
|
|
|
if (lastLineEmpty) { break; } |
|
|
|
|
|
|
|
// Case 3: another tag found.
|
|
|
|
if (rules_named.fences(state, nextLine, endLine, true)) { break; } |
|
|
|
if (rules_named.hr(state, nextLine, endLine, true)) { break; } |
|
|
|
if (rules_named.list(state, nextLine, endLine, true)) { break; } |
|
|
|
if (rules_named.heading(state, nextLine, endLine, true)) { break; } |
|
|
|
if (rules_named.lheading(state, nextLine, endLine, true)) { break; } |
|
|
|
if (rules_named.table(state, nextLine, endLine, true)) { break; } |
|
|
|
//if (rules_named.tag(state, nextLine, endLine, true)) { break; }
|
|
|
|
//if (rules_named.def(state, nextLine, endLine, true)) { break; }
|
|
|
|
while (nextLine < lineMax) { |
|
|
|
if (isEmpty(state, nextLine)) { break; } |
|
|
|
nextLine++; |
|
|
|
} |
|
|
|
subState = state.clone(getLines(state, startLine, nextLine, true) |
|
|
|
.replace(/^ {0,3}> ?/mg, '')); |
|
|
|
state.lexerBlock.tokenize(subState, 0, insideLines); |
|
|
|
nextLine = startLine = subState.line + startLine; |
|
|
|
insideLines = 0; |
|
|
|
} |
|
|
|
|
|
|
|
state.tokens.push({ type: 'blockquote_open' }); |
|
|
|
|
|
|
|
subState = state.clone(getLines(state, startLine, nextLine, true).replace(/^ {0,3}> ?/mg, '')); |
|
|
|
state.lexerBlock.tokenize(subState, 0, subState.lineMax); |
|
|
|
|
|
|
|
state.tokens.push({ type: 'blockquote_close' }); |
|
|
|
|
|
|
|
state.line = nextLine; |
|
|
|