HTML: Fix format on files with frontMatter (#9043)
This commit is contained in:
1 parent
9550428987
commit
720177ac5c
5 files changed
+83
No files matched your search
@@ -0,0 +1,23 @@
|
||||
#### Fix format on html with frontMatter ([#9043](https://github.com/prettier/prettier/pull/9043) by [@fisker](https://github.com/fisker))
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```html
|
||||
<!-- Input -->
|
||||
---
|
||||
layout: foo
|
||||
---
|
||||
|
||||
Test <a
|
||||
href="https://prettier.io">abc</a>.
|
||||
|
||||
<!-- Prettier stable -->
|
||||
TypeError: Cannot read property 'end' of undefined
|
||||
...
|
||||
|
||||
<!-- Prettier master -->
|
||||
---
|
||||
layout: foo
|
||||
---
|
||||
|
||||
Test <a href="https://prettier.io">abc</a>.
|
||||
```
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,3 +28,48 @@ 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>.
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
layout: foo
|
||||
---
|
||||
Test <a
|
||||
href="https://prettier.io">abc</a>.
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
layout: foo
|
||||
---
|
||||
|
||||
Test <a
|
||||
href="https://prettier.io">abc</a>.
|
||||
Reference in new issue
Block a user