Skip to content

Commit

Permalink
fix(markdown): identify CJK correctly (#5402)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatyang committed Nov 9, 2018
1 parent 1bce579 commit 4e7fca5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/language-markdown/constants.evaluate.js
Expand Up @@ -4,8 +4,23 @@ const cjkRegex = require("cjk-regex");
const regexpUtil = require("regexp-util");
const unicodeRegex = require("unicode-regex");

const cjkPattern = cjkRegex().toString();
const kPattern = unicodeRegex({ Script: ["Hangul"] }).toString();
const cjkPattern = cjkRegex()
.union(
unicodeRegex({
Script_Extensions: ["Han", "Katakana", "Hiragana", "Hangul", "Bopomofo"],
General_Category: [
"Other_Letter",
"Letter_Number",
"Other_Symbol",
"Modifier_Letter"
]
})
)
.toString();

const kPattern = unicodeRegex({ Script: ["Hangul"] })
.union(unicodeRegex({ Script_Extensions: ["Hangul"] }))
.toString();

// http://spec.commonmark.org/0.25/#ascii-punctuation-character
const asciiPunctuationCharset = /* prettier-ignore */ regexpUtil.charset(
Expand Down
4 changes: 4 additions & 0 deletions tests/markdown_splitCjkText/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -6,6 +6,8 @@ exports[`chinese-japanese.md - markdown-verify 1`] = `
全  形 空白全  形 空白全  形 空白全  形 空白全  形 空白全  形 空白全  形 空白
空白全形空白全形空白全形空白 空白全形空白全形空白全形空白 空白全形空白全形空白全形空白 空白全形空白全形空白全形空白
何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
這是一段很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長
很長的段落
Expand All @@ -16,6 +18,8 @@ exports[`chinese-japanese.md - markdown-verify 1`] = `
空白全形空白全形空白全形空白 空白全形空白全形空白全形空白 空白全形空白全形空白
全形空白 空白全形空白全形空白全形空白
何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。
`;

exports[`korean.md - markdown-verify 1`] = `
Expand Down
2 changes: 2 additions & 0 deletions tests/markdown_splitCjkText/chinese-japanese.md
Expand Up @@ -3,3 +3,5 @@
全  形 空白全  形 空白全  形 空白全  形 空白全  形 空白全  形 空白全  形 空白

空白全形空白全形空白全形空白 空白全形空白全形空白全形空白 空白全形空白全形空白全形空白 空白全形空白全形空白全形空白

何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。

0 comments on commit 4e7fca5

Please sign in to comment.