Skip to content

Commit

Permalink
Fix format on html with frontMatter
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Aug 25, 2020
1 parent 7e5f6b9 commit d3e2c22
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/language-html/parser-html.js
Expand Up @@ -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);
}

Expand Down
43 changes: 43 additions & 0 deletions tests/html/front-matter/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -28,3 +28,46 @@ slug: home
================================================================================
`;

exports[`issue-9042.html format 1`] = `
====================================options=====================================
parsers: ["html"]
printWidth: 80
| printWidth
=====================================input======================================
---
layout: foo
---
Test <a href="https://prettier.io">abc</a>.
=====================================output=====================================
---
layout: foo
---
Test <a href="https://prettier.io">abc</a>.
================================================================================
`;

exports[`issue-9042-no-empty-line.html format 1`] = `
====================================options=====================================
parsers: ["html"]
printWidth: 80
| printWidth
=====================================input======================================
---
layout: foo
---
Test <a href="https://prettier.io">abc</a>.
=====================================output=====================================
---
layout: foo
---
Test <a href="https://prettier.io">abc</a>.
================================================================================
`;
4 changes: 4 additions & 0 deletions tests/html/front-matter/issue-9042-no-empty-line.html
@@ -0,0 +1,4 @@
---
layout: foo
---
Test <a href="https://prettier.io">abc</a>.
5 changes: 5 additions & 0 deletions tests/html/front-matter/issue-9042.html
@@ -0,0 +1,5 @@
---
layout: foo
---

Test <a href="https://prettier.io">abc</a>.

0 comments on commit d3e2c22

Please sign in to comment.