From d3e2c2269ffd99b943b7165db4bdf50c55e1de39 Mon Sep 17 00:00:00 2001 From: fisker Date: Tue, 25 Aug 2020 12:11:52 +0800 Subject: [PATCH] Fix format on html with frontMatter --- src/language-html/parser-html.js | 4 ++ .../__snapshots__/jsfmt.spec.js.snap | 43 +++++++++++++++++++ .../issue-9042-no-empty-line.html | 4 ++ tests/html/front-matter/issue-9042.html | 5 +++ 4 files changed, 56 insertions(+) create mode 100644 tests/html/front-matter/issue-9042-no-empty-line.html create mode 100644 tests/html/front-matter/issue-9042.html diff --git a/src/language-html/parser-html.js b/src/language-html/parser-html.js index 7b1a93f7db1b..3dcdb4124336 100644 --- a/src/language-html/parser-html.js +++ b/src/language-html/parser-html.js @@ -280,6 +280,10 @@ function _parse(text, options, parserOptions, shouldParseFrontMatter = true) { }; if (frontMatter) { + frontMatter.sourceSpan = { + start: { offset: 0 }, + end: { offset: frontMatter.raw.length }, + }; rawAst.children.unshift(frontMatter); } diff --git a/tests/html/front-matter/__snapshots__/jsfmt.spec.js.snap b/tests/html/front-matter/__snapshots__/jsfmt.spec.js.snap index b79cca5d1846..41ee552bec41 100644 --- a/tests/html/front-matter/__snapshots__/jsfmt.spec.js.snap +++ b/tests/html/front-matter/__snapshots__/jsfmt.spec.js.snap @@ -28,3 +28,46 @@ slug: home ================================================================================ `; + +exports[`issue-9042.html format 1`] = ` +====================================options===================================== +parsers: ["html"] +printWidth: 80 + | printWidth +=====================================input====================================== +--- +layout: foo +--- + +Test abc. + +=====================================output===================================== +--- +layout: foo +--- + +Test abc. + +================================================================================ +`; + +exports[`issue-9042-no-empty-line.html format 1`] = ` +====================================options===================================== +parsers: ["html"] +printWidth: 80 + | printWidth +=====================================input====================================== +--- +layout: foo +--- +Test abc. + +=====================================output===================================== +--- +layout: foo +--- + +Test abc. + +================================================================================ +`; diff --git a/tests/html/front-matter/issue-9042-no-empty-line.html b/tests/html/front-matter/issue-9042-no-empty-line.html new file mode 100644 index 000000000000..a7d0c7f6a36f --- /dev/null +++ b/tests/html/front-matter/issue-9042-no-empty-line.html @@ -0,0 +1,4 @@ +--- +layout: foo +--- +Test abc. diff --git a/tests/html/front-matter/issue-9042.html b/tests/html/front-matter/issue-9042.html new file mode 100644 index 000000000000..e37dadb431dc --- /dev/null +++ b/tests/html/front-matter/issue-9042.html @@ -0,0 +1,5 @@ +--- +layout: foo +--- + +Test abc.