Markdown: Fix parse error in liquid plugin (#19411)
Co-authored-by: Codex <noreply@openai.com> Co-authored-by: fisker Cheung <lionkay@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
4 files changed
+220
-16
No files matched your search
@@ -17,12 +17,12 @@ const nodeType = "liquidNode";
|
||||
function liquidFromMarkdown() {
|
||||
return {
|
||||
canContainEols: [nodeType],
|
||||
enter: { [nodeType]: enterInlineMath },
|
||||
exit: { [nodeType]: exitInlineMath },
|
||||
enter: { [nodeType]: enter },
|
||||
exit: { [nodeType]: exit },
|
||||
};
|
||||
|
||||
/** @type {Handle} */
|
||||
function enterInlineMath(token) {
|
||||
function enter(token) {
|
||||
this.enter(
|
||||
// @ts-expect-error
|
||||
{ type: nodeType },
|
||||
@@ -32,7 +32,7 @@ function liquidFromMarkdown() {
|
||||
}
|
||||
|
||||
/** @type {Handle} */
|
||||
function exitInlineMath(token) {
|
||||
function exit(token) {
|
||||
const d = this.resume();
|
||||
/** @type {any} */
|
||||
const node = this.stack.at(-1);
|
||||
@@ -49,12 +49,12 @@ function liquidSyntax() {
|
||||
text: {
|
||||
[codes.leftCurlyBrace]: {
|
||||
name: "liquid",
|
||||
tokenize: liquidTokenize,
|
||||
tokenize,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
function liquidTokenize(effects, ok, nok) {
|
||||
function tokenize(effects, ok, nok) {
|
||||
return start;
|
||||
|
||||
/** @type {State} */
|
||||
@@ -69,7 +69,7 @@ function liquidSyntax() {
|
||||
effects.consume(code);
|
||||
return inside;
|
||||
default:
|
||||
return nok;
|
||||
return nok(code);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -79,28 +79,61 @@ function liquidSyntax() {
|
||||
switch (code) {
|
||||
case codes.percentSign:
|
||||
case codes.rightCurlyBrace:
|
||||
effects.consume(code);
|
||||
return mayExit;
|
||||
return effects.check({ tokenize: tokenizeClose }, close, data)(code);
|
||||
case codes.eof:
|
||||
return nok;
|
||||
return nok(code);
|
||||
default:
|
||||
if (markdownLineEnding(code)) {
|
||||
effects.exit(types.data);
|
||||
effects.enter(types.lineEnding);
|
||||
effects.consume(code);
|
||||
effects.exit(types.lineEnding);
|
||||
effects.enter(types.data);
|
||||
return inside;
|
||||
}
|
||||
effects.consume(code);
|
||||
return inside;
|
||||
return data(code);
|
||||
}
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function mayExit(code) {
|
||||
if (code !== codes.rightCurlyBrace) {
|
||||
effects.consume(code);
|
||||
return inside;
|
||||
function data(code) {
|
||||
effects.consume(code);
|
||||
return inside;
|
||||
}
|
||||
|
||||
function tokenizeClose(effects, ok, nok) {
|
||||
return startClose;
|
||||
|
||||
/** @type {State} */
|
||||
function startClose(code) {
|
||||
switch (code) {
|
||||
case codes.percentSign:
|
||||
case codes.rightCurlyBrace:
|
||||
effects.consume(code);
|
||||
return endClose;
|
||||
default:
|
||||
return nok(code);
|
||||
}
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function endClose(code) {
|
||||
if (code !== codes.rightCurlyBrace) {
|
||||
return nok(code);
|
||||
}
|
||||
effects.consume(code);
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function close(code) {
|
||||
effects.consume(code);
|
||||
return closeEnd;
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function closeEnd(code) {
|
||||
effects.consume(code);
|
||||
effects.exit(types.data);
|
||||
effects.exit(nodeType);
|
||||
|
||||
@@ -70,6 +70,152 @@ where does it end }}
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`example-2.md - {"proseWrap":"always"} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["markdown"]
|
||||
proseWrap: "always"
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
# linebreak after opening brace
|
||||
|
||||
{
|
||||
|
||||
---
|
||||
|
||||
# including empty lines
|
||||
|
||||
{{ foo
|
||||
|
||||
bar baz
|
||||
|
||||
qux }}
|
||||
|
||||
---
|
||||
|
||||
# line break after %
|
||||
|
||||
{% foo %
|
||||
|
||||
bar baz %}
|
||||
|
||||
=====================================output=====================================
|
||||
# linebreak after opening brace
|
||||
|
||||
{
|
||||
|
||||
---
|
||||
|
||||
# including empty lines
|
||||
|
||||
{{ foo
|
||||
|
||||
bar baz
|
||||
|
||||
qux }}
|
||||
|
||||
---
|
||||
|
||||
# line break after %
|
||||
|
||||
{% foo %
|
||||
|
||||
bar baz %}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`example-2.md format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["markdown"]
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
# linebreak after opening brace
|
||||
|
||||
{
|
||||
|
||||
---
|
||||
|
||||
# including empty lines
|
||||
|
||||
{{ foo
|
||||
|
||||
bar baz
|
||||
|
||||
qux }}
|
||||
|
||||
---
|
||||
|
||||
# line break after %
|
||||
|
||||
{% foo %
|
||||
|
||||
bar baz %}
|
||||
|
||||
=====================================output=====================================
|
||||
# linebreak after opening brace
|
||||
|
||||
{
|
||||
|
||||
---
|
||||
|
||||
# including empty lines
|
||||
|
||||
{{ foo
|
||||
|
||||
bar baz
|
||||
|
||||
qux }}
|
||||
|
||||
---
|
||||
|
||||
# line break after %
|
||||
|
||||
{% foo %
|
||||
|
||||
bar baz %}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`issue-19386.md - {"proseWrap":"always"} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["markdown"]
|
||||
proseWrap: "always"
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
{{ rule({
|
||||
categories: {
|
||||
}
|
||||
}) }}
|
||||
|
||||
=====================================output=====================================
|
||||
{{ rule({
|
||||
categories: {
|
||||
}
|
||||
}) }}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`issue-19386.md format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["markdown"]
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
{{ rule({
|
||||
categories: {
|
||||
}
|
||||
}) }}
|
||||
|
||||
=====================================output=====================================
|
||||
{{ rule({
|
||||
categories: {
|
||||
}
|
||||
}) }}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`unbalanced-mismatched-braces.md - {"proseWrap":"always"} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["markdown"]
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# linebreak after opening brace
|
||||
|
||||
{
|
||||
|
||||
---
|
||||
|
||||
# including empty lines
|
||||
|
||||
{{ foo
|
||||
|
||||
bar baz
|
||||
|
||||
qux }}
|
||||
|
||||
---
|
||||
|
||||
# line break after %
|
||||
|
||||
{% foo %
|
||||
|
||||
bar baz %}
|
||||
@@ -0,0 +1,4 @@
|
||||
{{ rule({
|
||||
categories: {
|
||||
}
|
||||
}) }}
|
||||
Reference in new issue
Block a user