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() {
|
function liquidFromMarkdown() {
|
||||||
return {
|
return {
|
||||||
canContainEols: [nodeType],
|
canContainEols: [nodeType],
|
||||||
enter: { [nodeType]: enterInlineMath },
|
enter: { [nodeType]: enter },
|
||||||
exit: { [nodeType]: exitInlineMath },
|
exit: { [nodeType]: exit },
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @type {Handle} */
|
/** @type {Handle} */
|
||||||
function enterInlineMath(token) {
|
function enter(token) {
|
||||||
this.enter(
|
this.enter(
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
{ type: nodeType },
|
{ type: nodeType },
|
||||||
@@ -32,7 +32,7 @@ function liquidFromMarkdown() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @type {Handle} */
|
/** @type {Handle} */
|
||||||
function exitInlineMath(token) {
|
function exit(token) {
|
||||||
const d = this.resume();
|
const d = this.resume();
|
||||||
/** @type {any} */
|
/** @type {any} */
|
||||||
const node = this.stack.at(-1);
|
const node = this.stack.at(-1);
|
||||||
@@ -49,12 +49,12 @@ function liquidSyntax() {
|
|||||||
text: {
|
text: {
|
||||||
[codes.leftCurlyBrace]: {
|
[codes.leftCurlyBrace]: {
|
||||||
name: "liquid",
|
name: "liquid",
|
||||||
tokenize: liquidTokenize,
|
tokenize,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function liquidTokenize(effects, ok, nok) {
|
function tokenize(effects, ok, nok) {
|
||||||
return start;
|
return start;
|
||||||
|
|
||||||
/** @type {State} */
|
/** @type {State} */
|
||||||
@@ -69,7 +69,7 @@ function liquidSyntax() {
|
|||||||
effects.consume(code);
|
effects.consume(code);
|
||||||
return inside;
|
return inside;
|
||||||
default:
|
default:
|
||||||
return nok;
|
return nok(code);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -79,28 +79,61 @@ function liquidSyntax() {
|
|||||||
switch (code) {
|
switch (code) {
|
||||||
case codes.percentSign:
|
case codes.percentSign:
|
||||||
case codes.rightCurlyBrace:
|
case codes.rightCurlyBrace:
|
||||||
effects.consume(code);
|
return effects.check({ tokenize: tokenizeClose }, close, data)(code);
|
||||||
return mayExit;
|
|
||||||
case codes.eof:
|
case codes.eof:
|
||||||
return nok;
|
return nok(code);
|
||||||
default:
|
default:
|
||||||
if (markdownLineEnding(code)) {
|
if (markdownLineEnding(code)) {
|
||||||
|
effects.exit(types.data);
|
||||||
effects.enter(types.lineEnding);
|
effects.enter(types.lineEnding);
|
||||||
effects.consume(code);
|
effects.consume(code);
|
||||||
effects.exit(types.lineEnding);
|
effects.exit(types.lineEnding);
|
||||||
|
effects.enter(types.data);
|
||||||
return inside;
|
return inside;
|
||||||
}
|
}
|
||||||
effects.consume(code);
|
return data(code);
|
||||||
return inside;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {State} */
|
/** @type {State} */
|
||||||
function mayExit(code) {
|
function data(code) {
|
||||||
if (code !== codes.rightCurlyBrace) {
|
effects.consume(code);
|
||||||
effects.consume(code);
|
return inside;
|
||||||
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.consume(code);
|
||||||
effects.exit(types.data);
|
effects.exit(types.data);
|
||||||
effects.exit(nodeType);
|
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`] = `
|
exports[`unbalanced-mismatched-braces.md - {"proseWrap":"always"} format 1`] = `
|
||||||
====================================options=====================================
|
====================================options=====================================
|
||||||
parsers: ["markdown"]
|
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