Fix lazy lines
This commit is contained in:
parent
d40008f5c7
commit
d9489c7489
2 changed files with 88 additions and 12 deletions
|
@ -23,6 +23,7 @@ export const directiveContainer = {
|
||||||
|
|
||||||
const label = {tokenize: tokenizeLabel, partial: true}
|
const label = {tokenize: tokenizeLabel, partial: true}
|
||||||
const attributes = {tokenize: tokenizeAttributes, partial: true}
|
const attributes = {tokenize: tokenizeAttributes, partial: true}
|
||||||
|
const nonLazyLine = {tokenize: tokenizeNonLazyLine, partial: true}
|
||||||
|
|
||||||
/** @type {Tokenizer} */
|
/** @type {Tokenizer} */
|
||||||
function tokenizeDirectiveContainer(effects, ok, nok) {
|
function tokenizeDirectiveContainer(effects, ok, nok) {
|
||||||
|
@ -93,20 +94,26 @@ function tokenizeDirectiveContainer(effects, ok, nok) {
|
||||||
effects.exit('directiveContainerFence')
|
effects.exit('directiveContainerFence')
|
||||||
|
|
||||||
if (code === codes.eof) {
|
if (code === codes.eof) {
|
||||||
effects.exit('directiveContainer')
|
return afterOpening(code)
|
||||||
return ok(code)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (markdownLineEnding(code)) {
|
if (markdownLineEnding(code)) {
|
||||||
effects.enter(types.lineEnding)
|
if (self.interrupt) {
|
||||||
effects.consume(code)
|
return ok(code)
|
||||||
effects.exit(types.lineEnding)
|
}
|
||||||
return self.interrupt ? ok : contentStart
|
|
||||||
|
return effects.attempt(nonLazyLine, contentStart, afterOpening)(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nok(code)
|
return nok(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @type {State} */
|
||||||
|
function afterOpening(code) {
|
||||||
|
effects.exit('directiveContainer')
|
||||||
|
return ok(code)
|
||||||
|
}
|
||||||
|
|
||||||
/** @type {State} */
|
/** @type {State} */
|
||||||
function contentStart(code) {
|
function contentStart(code) {
|
||||||
if (code === codes.eof) {
|
if (code === codes.eof) {
|
||||||
|
@ -157,14 +164,26 @@ function tokenizeDirectiveContainer(effects, ok, nok) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (markdownLineEnding(code)) {
|
if (markdownLineEnding(code)) {
|
||||||
|
return effects.check(nonLazyLine, nonLazyLineAfter, lineAfter)(code)
|
||||||
|
}
|
||||||
|
|
||||||
|
effects.consume(code)
|
||||||
|
return contentContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @type {State} */
|
||||||
|
function nonLazyLineAfter(code) {
|
||||||
effects.consume(code)
|
effects.consume(code)
|
||||||
const t = effects.exit(types.chunkDocument)
|
const t = effects.exit(types.chunkDocument)
|
||||||
self.parser.lazy[t.start.line] = false
|
self.parser.lazy[t.start.line] = false
|
||||||
return lineStart
|
return lineStart
|
||||||
}
|
}
|
||||||
|
|
||||||
effects.consume(code)
|
/** @type {State} */
|
||||||
return contentContinue
|
function lineAfter(code) {
|
||||||
|
const t = effects.exit(types.chunkDocument)
|
||||||
|
self.parser.lazy[t.start.line] = false
|
||||||
|
return after(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {State} */
|
/** @type {State} */
|
||||||
|
@ -252,3 +271,24 @@ function tokenizeAttributes(effects, ok, nok) {
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @type {Tokenizer} */
|
||||||
|
function tokenizeNonLazyLine(effects, ok, nok) {
|
||||||
|
const self = this
|
||||||
|
|
||||||
|
return start
|
||||||
|
|
||||||
|
/** @type {State} */
|
||||||
|
function start(code) {
|
||||||
|
assert(markdownLineEnding(code), 'expected eol')
|
||||||
|
effects.enter(types.lineEnding)
|
||||||
|
effects.consume(code)
|
||||||
|
effects.exit(types.lineEnding)
|
||||||
|
return lineStart
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @type {State} */
|
||||||
|
function lineStart(code) {
|
||||||
|
return self.parser.lazy[self.now().line] ? nok(code) : ok(code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -710,6 +710,18 @@ test('micromark-extension-directive (syntax)', (t) => {
|
||||||
'should support a thematic break before a leaf'
|
'should support a thematic break before a leaf'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
t.equal(
|
||||||
|
micromark('> ::a\nb', options({'*': h})),
|
||||||
|
'<blockquote><a></a>\n</blockquote>\n<p>b</p>',
|
||||||
|
'should not support lazyness (1)'
|
||||||
|
)
|
||||||
|
|
||||||
|
t.equal(
|
||||||
|
micromark('> a\n::b', options({'*': h})),
|
||||||
|
'<blockquote>\n<p>a</p>\n</blockquote>\n<b></b>',
|
||||||
|
'should not support lazyness (2)'
|
||||||
|
)
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1032,7 +1044,7 @@ test('micromark-extension-directive (syntax)', (t) => {
|
||||||
|
|
||||||
t.equal(
|
t.equal(
|
||||||
micromark('>a\n:::a\nb', options()),
|
micromark('>a\n:::a\nb', options()),
|
||||||
'<blockquote>\n<p>a</p>\n</blockquote>',
|
'<blockquote>\n<p>a</p>\n</blockquote>\n',
|
||||||
'should support a block quote before a container'
|
'should support a block quote before a container'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1074,7 +1086,7 @@ test('micromark-extension-directive (syntax)', (t) => {
|
||||||
|
|
||||||
t.equal(
|
t.equal(
|
||||||
micromark('* a\n:::a\nb', options()),
|
micromark('* a\n:::a\nb', options()),
|
||||||
'<ul>\n<li>a</li>\n</ul>',
|
'<ul>\n<li>a</li>\n</ul>\n',
|
||||||
'should support a list before a container'
|
'should support a list before a container'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1114,6 +1126,30 @@ test('micromark-extension-directive (syntax)', (t) => {
|
||||||
'should support prefixed containers (4)'
|
'should support prefixed containers (4)'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
t.equal(
|
||||||
|
micromark('> :::a\nb', options({'*': h})),
|
||||||
|
'<blockquote><a></a>\n</blockquote>\n<p>b</p>',
|
||||||
|
'should not support lazyness (1)'
|
||||||
|
)
|
||||||
|
|
||||||
|
t.equal(
|
||||||
|
micromark('> :::a\n> b\nc', options({'*': h})),
|
||||||
|
'<blockquote><a>\n<p>b</p>\n</a>\n</blockquote>\n<p>c</p>',
|
||||||
|
'should not support lazyness (2)'
|
||||||
|
)
|
||||||
|
|
||||||
|
t.equal(
|
||||||
|
micromark('> a\n:::b', options({'*': h})),
|
||||||
|
'<blockquote>\n<p>a</p>\n</blockquote>\n<b></b>',
|
||||||
|
'should not support lazyness (3)'
|
||||||
|
)
|
||||||
|
|
||||||
|
t.equal(
|
||||||
|
micromark('> :::a\n:::', options({'*': h})),
|
||||||
|
'<blockquote><a></a>\n</blockquote>\n<p>:::</p>',
|
||||||
|
'should not support lazyness (4)'
|
||||||
|
)
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue