diff --git a/src/language-markdown/parser-markdown.js b/src/language-markdown/parser-markdown.js index 47676d782..419c7345f 100644 --- a/src/language-markdown/parser-markdown.js +++ b/src/language-markdown/parser-markdown.js @@ -6,6 +6,9 @@ const pragma = require("./pragma"); const parseFrontMatter = require("../utils/front-matter"); const util = require("../common/util"); +// 0x0 ~ 0x10ffff +const isSingleCharRegex = /^([\u0000-\uffff]|[\ud800-\udbff][\udc00-\udfff])$/; + /** * based on [MDAST](https://github.com/syntax-tree/mdast) with following modifications: * @@ -66,8 +69,9 @@ function restoreUnescapedCharacter(originalText) { value: node.value !== "*" && node.value !== "_" && // handle these two cases in printer - node.value.length === 1 && - node.position.end.offset - node.position.start.offset > 1 + isSingleCharRegex.test(node.value) && + node.position.end.offset - node.position.start.offset !== + node.value.length ? originalText.slice( node.position.start.offset, node.position.end.offset diff --git a/tests/markdown_word/__snapshots__/jsfmt.spec.js.snap b/tests/markdown_word/__snapshots__/jsfmt.spec.js.snap index c032f2d2f..526035e91 100644 --- a/tests/markdown_word/__snapshots__/jsfmt.spec.js.snap +++ b/tests/markdown_word/__snapshots__/jsfmt.spec.js.snap @@ -18,6 +18,18 @@ asd & asd „ 123 123 * 123 * 123 ## 类的 prototype 属性和\\_\\_proto\\_\\_属性 + +123�123 + +123#123 + +123Ϡ123 + +123😉123 + +123"123 + +123�123 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ hello \\* world \\_ ~~ ya @@ -37,4 +49,16 @@ asd & asd „ 123 ## 类的 prototype 属性和\\_\\_proto\\_\\_属性 +123�123 + +123#123 + +123Ϡ123 + +123😉123 + +123"123 + +123�123 + `; diff --git a/tests/markdown_word/escape.md b/tests/markdown_word/escape.md index e4bc56016..07b40ab92 100644 --- a/tests/markdown_word/escape.md +++ b/tests/markdown_word/escape.md @@ -15,3 +15,15 @@ asd & asd „ 123 123 * 123 * 123 ## 类的 prototype 属性和\_\_proto\_\_属性 + +123�123 + +123#123 + +123Ϡ123 + +123😉123 + +123"123 + +123�123