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.