fix(markdown): preserve entity for surrogate pair (#4832)

master
Ika 2018-07-12 21:42:39 +08:00 committed by GitHub
parent 85eb3b63ad
commit cd16ff27d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 2 deletions

View File

@ -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

View File

@ -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
`;

View File

@ -15,3 +15,15 @@ asd & asd „ 123
123 * 123 * 123
## 类的 prototype 属性和\_\_proto\_\_属性
123�123
123#123
123Ϡ123
123😉123
123"123
123�123