Correct frontmatter length measurement (#18453)
This commit is contained in:
1 parent
a9c0ce927b
commit
f2cfef1ec2
6 files changed
+84
-1
No files matched your search
@@ -0,0 +1,26 @@
|
||||
#### Fix a bug around unicode in front matter (#18453 by @seiyab)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```html
|
||||
<!-- Input -->
|
||||
---
|
||||
title: 😄
|
||||
---
|
||||
|
||||
<!-- comment -->
|
||||
|
||||
<!-- Prettier stable -->
|
||||
---
|
||||
title: 😄
|
||||
---
|
||||
|
||||
|
||||
<!-- comment --
|
||||
|
||||
<!-- Prettier main -->
|
||||
---
|
||||
title: 😄
|
||||
---
|
||||
|
||||
<!-- comment -->
|
||||
```
|
||||
@@ -106,7 +106,10 @@ function parse(text) {
|
||||
frontMatter,
|
||||
get content() {
|
||||
const { raw } = frontMatter;
|
||||
return raw.replaceAll(/[^\n]/gu, " ") + text.slice(raw.length);
|
||||
return (
|
||||
// eslint-disable-next-line require-unicode-regexp -- string length matters so intentionally not using unicode flag
|
||||
raw.replaceAll(/[^\n]/g, " ") + text.slice(raw.length)
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -116,3 +116,25 @@ Test <a href="https://prettier.io">abc</a>.
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`unicode.html format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["html"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
---
|
||||
title: "ABC 漢字 🇯🇵"
|
||||
---
|
||||
|
||||
<!-- this is a comment -->
|
||||
|
||||
=====================================output=====================================
|
||||
---
|
||||
title: "ABC 漢字 🇯🇵"
|
||||
---
|
||||
|
||||
<!-- this is a comment -->
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
title: "ABC 漢字 🇯🇵"
|
||||
---
|
||||
|
||||
<!-- this is a comment -->
|
||||
@@ -79,3 +79,25 @@ text
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`unicode.md format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["markdown"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
---
|
||||
title: "ABC 漢字 🇯🇵"
|
||||
---
|
||||
|
||||
## Retrospective
|
||||
|
||||
=====================================output=====================================
|
||||
---
|
||||
title: "ABC 漢字 🇯🇵"
|
||||
---
|
||||
|
||||
## Retrospective
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
title: "ABC 漢字 🇯🇵"
|
||||
---
|
||||
|
||||
## Retrospective
|
||||
Reference in new issue
Block a user