fix(markdown): do not merge continuous cjk if proseWrap=preserve (#4504)
* test: add tests * fix(markdown): do not merge continuous cjk if proseWrap=preserve * fix: remove trailing comma for node4master
parent
ea01781d8c
commit
a9eb68296c
|
@ -612,15 +612,17 @@ function getMaxContinuousCount(str, target) {
|
|||
* @param {string} text
|
||||
* @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
|
||||
*/
|
||||
function splitText(text) {
|
||||
function splitText(text, options) {
|
||||
const KIND_NON_CJK = "non-cjk";
|
||||
const KIND_CJK_CHARACTER = "cjk-character";
|
||||
const KIND_CJK_PUNCTUATION = "cjk-punctuation";
|
||||
|
||||
const nodes = [];
|
||||
|
||||
text
|
||||
.replace(new RegExp(`(${cjkPattern})\n(${cjkPattern})`, "g"), "$1$2")
|
||||
(options.proseWrap === "preserve"
|
||||
? text
|
||||
: text.replace(new RegExp(`(${cjkPattern})\n(${cjkPattern})`, "g"), "$1$2")
|
||||
)
|
||||
.split(/([ \t\n]+)/)
|
||||
.forEach((token, index, tokens) => {
|
||||
// whitespace
|
||||
|
|
|
@ -19,7 +19,7 @@ const util = require("../common/util");
|
|||
* interface Sentence { children: Array<Word | Whitespace> }
|
||||
* interface InlineCode { children: Array<Sentence> }
|
||||
*/
|
||||
function parse(text /*, parsers, opts*/) {
|
||||
function parse(text, parsers, opts) {
|
||||
const processor = unified()
|
||||
.use(remarkParse, { footnotes: true, commonmark: true })
|
||||
.use(frontmatter)
|
||||
|
@ -27,7 +27,7 @@ function parse(text /*, parsers, opts*/) {
|
|||
.use(restoreUnescapedCharacter(text))
|
||||
.use(mergeContinuousTexts)
|
||||
.use(transformInlineCode)
|
||||
.use(splitText);
|
||||
.use(splitText(opts));
|
||||
return processor.runSync(processor.parse(text));
|
||||
}
|
||||
|
||||
|
@ -102,8 +102,8 @@ function mergeContinuousTexts() {
|
|||
});
|
||||
}
|
||||
|
||||
function splitText() {
|
||||
return ast =>
|
||||
function splitText(options) {
|
||||
return () => ast =>
|
||||
map(ast, (node, index, parentNode) => {
|
||||
if (node.type !== "text") {
|
||||
return node;
|
||||
|
@ -123,7 +123,7 @@ function splitText() {
|
|||
return {
|
||||
type: "sentence",
|
||||
position: node.position,
|
||||
children: util.splitText(value)
|
||||
children: util.splitText(value, options)
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
|
@ -55,7 +55,8 @@ function genericPrint(path, options, print) {
|
|||
options.originalText.slice(
|
||||
node.position.start.offset,
|
||||
node.position.end.offset
|
||||
)
|
||||
),
|
||||
options
|
||||
)
|
||||
.map(
|
||||
node =>
|
||||
|
|
|
@ -12,6 +12,10 @@ This ia an english paragraph with a CJK quote "中文".
|
|||
This ia an english paragraph with a CJK quote “中文“.
|
||||
|
||||
扩展运算符(spread)是三个点(\`...\`)。
|
||||
|
||||
::: warning 注意
|
||||
该网站在国外无法访问,故以下演示无效
|
||||
:::
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
這是一段很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長
|
||||
很長的段落
|
||||
|
@ -36,6 +40,8 @@ This ia an english paragraph with a CJK quote “中文“.
|
|||
|
||||
扩展运算符(spread)是三个点(\`...\`)。
|
||||
|
||||
::: warning 注意该网站在国外无法访问,故以下演示无效 :::
|
||||
|
||||
`;
|
||||
|
||||
exports[`cjk.md 2`] = `
|
||||
|
@ -50,6 +56,10 @@ This ia an english paragraph with a CJK quote "中文".
|
|||
This ia an english paragraph with a CJK quote “中文“.
|
||||
|
||||
扩展运算符(spread)是三个点(\`...\`)。
|
||||
|
||||
::: warning 注意
|
||||
该网站在国外无法访问,故以下演示无效
|
||||
:::
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
這是一段很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長的段落
|
||||
|
||||
|
@ -63,6 +73,8 @@ This ia an english paragraph with a CJK quote “中文“.
|
|||
|
||||
扩展运算符(spread)是三个点(\`...\`)。
|
||||
|
||||
::: warning 注意该网站在国外无法访问,故以下演示无效 :::
|
||||
|
||||
`;
|
||||
|
||||
exports[`cjk.md 3`] = `
|
||||
|
@ -77,6 +89,10 @@ This ia an english paragraph with a CJK quote "中文".
|
|||
This ia an english paragraph with a CJK quote “中文“.
|
||||
|
||||
扩展运算符(spread)是三个点(\`...\`)。
|
||||
|
||||
::: warning 注意
|
||||
该网站在国外无法访问,故以下演示无效
|
||||
:::
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
這是一段很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長的段落
|
||||
|
||||
|
@ -90,6 +106,10 @@ This ia an english paragraph with a CJK quote “中文“.
|
|||
|
||||
扩展运算符(spread)是三个点(\`...\`)。
|
||||
|
||||
::: warning 注意
|
||||
该网站在国外无法访问,故以下演示无效
|
||||
:::
|
||||
|
||||
`;
|
||||
|
||||
exports[`inline-nodes.md 1`] = `
|
||||
|
|
|
@ -9,3 +9,7 @@ This ia an english paragraph with a CJK quote "中文".
|
|||
This ia an english paragraph with a CJK quote “中文“.
|
||||
|
||||
扩展运算符(spread)是三个点(`...`)。
|
||||
|
||||
::: warning 注意
|
||||
该网站在国外无法访问,故以下演示无效
|
||||
:::
|
||||
|
|
Loading…
Reference in New Issue