From 0f8cc01aa51b9459b729190fb718978fa007f688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=95=E3=81=A3=E3=81=A1=E3=82=83=E3=82=93?= Date: Mon, 8 Jun 2020 16:01:31 +0900 Subject: [PATCH] Correctly format CJK sentences with Variation Selector. (#8511) * Correctly format CJK sentences with IVS. * Changelog pr-8511 * Changelog title should contain the title * GitHub user name can contain `-`. https://github.com/prettier/prettier/pull/8511#issuecomment-640231668 --- changelog_unreleased/markdown/pr-8511.md | 13 +++++++++++++ cspell.json | 2 +- src/language-markdown/constants.evaluate.js | 6 ++++-- .../paragraph/__snapshots__/jsfmt.spec.js.snap | 12 ++++++++++++ tests/markdown/paragraph/cjk.md | 2 ++ 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 changelog_unreleased/markdown/pr-8511.md diff --git a/changelog_unreleased/markdown/pr-8511.md b/changelog_unreleased/markdown/pr-8511.md new file mode 100644 index 000000000..3b2bf3ada --- /dev/null +++ b/changelog_unreleased/markdown/pr-8511.md @@ -0,0 +1,13 @@ +#### Correctly format CJK sentences with Variation Selector ([#8511](https://github.com/prettier/prettier/pull/8511) by [@ne-sachirou](https://github.com/ne-sachirou)) + + +```markdown + +麻󠄁羽󠄀‼️ + + +麻 󠄁 羽 󠄀 ‼️ + + +麻󠄁羽󠄀‼️ +``` diff --git a/cspell.json b/cspell.json index 7c12cb021..02589372c 100644 --- a/cspell.json +++ b/cspell.json @@ -387,7 +387,7 @@ ], "ignoreRegExpList": [ "\\n(`{3,})\\w*\\n[\\s\\S]+?\\1", - "\\[(\\*{2})?@\\w+?\\1\\]", + "\\[(\\*{2})?@[-\\w]+?\\1\\]", "\\[`\\w+`\\]", "ve{2,}r{2,}y", "ve+r+y+long\\w*", diff --git a/src/language-markdown/constants.evaluate.js b/src/language-markdown/constants.evaluate.js index 71ae1dd03..1b9ab9d09 100644 --- a/src/language-markdown/constants.evaluate.js +++ b/src/language-markdown/constants.evaluate.js @@ -4,7 +4,7 @@ const cjkRegex = require("cjk-regex"); const regexpUtil = require("regexp-util"); const unicodeRegex = require("unicode-regex"); -const cjkPattern = cjkRegex() +const cjkPattern = `(?:${cjkRegex() .union( unicodeRegex({ Script_Extensions: ["Han", "Katakana", "Hiragana", "Hangul", "Bopomofo"], @@ -18,7 +18,9 @@ const cjkPattern = cjkRegex() ], }) ) - .toString(); + .toString()})(?:${unicodeRegex({ + Block: ["Variation_Selectors", "Variation_Selectors_Supplement"], +}).toString()})?`; const kPattern = unicodeRegex({ Script: ["Hangul"] }) .union(unicodeRegex({ Script_Extensions: ["Hangul"] })) diff --git a/tests/markdown/paragraph/__snapshots__/jsfmt.spec.js.snap b/tests/markdown/paragraph/__snapshots__/jsfmt.spec.js.snap index c0f488ff4..a83ea1754 100644 --- a/tests/markdown/paragraph/__snapshots__/jsfmt.spec.js.snap +++ b/tests/markdown/paragraph/__snapshots__/jsfmt.spec.js.snap @@ -23,6 +23,8 @@ This ia an english paragraph with a CJK quote “中文“. 该网站在国外无法访问,故以下演示无效 ::: +IVS 麻󠄁羽󠄀‼️ + =====================================output===================================== 這是一段很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長 很長的段落 @@ -49,6 +51,8 @@ This ia an english paragraph with a CJK quote “中文“. ::: warning 注意该网站在国外无法访问,故以下演示无效 ::: +IVS 麻󠄁羽󠄀‼️ + ================================================================================ `; @@ -75,6 +79,8 @@ This ia an english paragraph with a CJK quote “中文“. 该网站在国外无法访问,故以下演示无效 ::: +IVS 麻󠄁羽󠄀‼️ + =====================================output===================================== 這是一段很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長的段落 @@ -90,6 +96,8 @@ This ia an english paragraph with a CJK quote “中文“. ::: warning 注意该网站在国外无法访问,故以下演示无效 ::: +IVS 麻󠄁羽󠄀‼️ + ================================================================================ `; @@ -116,6 +124,8 @@ This ia an english paragraph with a CJK quote “中文“. 该网站在国外无法访问,故以下演示无效 ::: +IVS 麻󠄁羽󠄀‼️ + =====================================output===================================== 這是一段很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長的段落 @@ -133,6 +143,8 @@ This ia an english paragraph with a CJK quote “中文“. 该网站在国外无法访问,故以下演示无效 ::: +IVS 麻󠄁羽󠄀‼️ + ================================================================================ `; diff --git a/tests/markdown/paragraph/cjk.md b/tests/markdown/paragraph/cjk.md index 3687d01fd..ba29c5ccc 100644 --- a/tests/markdown/paragraph/cjk.md +++ b/tests/markdown/paragraph/cjk.md @@ -13,3 +13,5 @@ This ia an english paragraph with a CJK quote “中文“. ::: warning 注意 该网站在国外无法访问,故以下演示无效 ::: + +IVS 麻󠄁羽󠄀‼️