Switch PUNCTUATION_REGEXP to use RegExp with u directly (#15621)
This commit is contained in:
1 parent
ccde7ca268
commit
d6daeec0a3
4 files changed
+57
-30
No files matched your search
@@ -90,7 +90,6 @@
|
||||
"postcss-scss": "4.0.9",
|
||||
"postcss-selector-parser": "2.2.3",
|
||||
"postcss-values-parser": "2.0.1",
|
||||
"regexp-util": "2.0.0",
|
||||
"remark-footnotes": "2.0.0",
|
||||
"remark-math": "3.0.1",
|
||||
"remark-parse": "8.0.3",
|
||||
|
||||
@@ -24,32 +24,61 @@ const CJK_REGEXP = new RegExp(
|
||||
`(?:${cjkCharset.toString()})(?:${variationSelectorsCharset.toString()})?`,
|
||||
);
|
||||
|
||||
// http://spec.commonmark.org/0.25/#ascii-punctuation-character
|
||||
const asciiPunctuationCharset =
|
||||
/* prettier-ignore */ new Charset(
|
||||
"!", '"', "#", "$", "%", "&", "'", "(", ")", "*",
|
||||
"+", ",", "-", ".", "/", ":", ";", "<", "=", ">",
|
||||
"?", "@", "[", "\\", "]", "^", "_", "`", "{", "|",
|
||||
"}", "~"
|
||||
const asciiPunctuationCharacters = [
|
||||
"!",
|
||||
'"',
|
||||
"#",
|
||||
"$",
|
||||
"%",
|
||||
"&",
|
||||
"'",
|
||||
"(",
|
||||
")",
|
||||
"*",
|
||||
"+",
|
||||
",",
|
||||
"-",
|
||||
".",
|
||||
"/",
|
||||
":",
|
||||
";",
|
||||
"<",
|
||||
"=",
|
||||
">",
|
||||
"?",
|
||||
"@",
|
||||
"[",
|
||||
"\\",
|
||||
"]",
|
||||
"^",
|
||||
"_",
|
||||
"`",
|
||||
"{",
|
||||
"|",
|
||||
"}",
|
||||
"~",
|
||||
];
|
||||
|
||||
// https://spec.commonmark.org/0.25/#punctuation-character
|
||||
// https://unicode.org/Public/5.1.0/ucd/UCD.html#General_Category_Values
|
||||
const unicodePunctuationClasses = [
|
||||
/* Pc */ "Connector_Punctuation",
|
||||
/* Pd */ "Dash_Punctuation",
|
||||
/* Pe */ "Close_Punctuation",
|
||||
/* Pf */ "Final_Punctuation",
|
||||
/* Pi */ "Initial_Punctuation",
|
||||
/* Po */ "Other_Punctuation",
|
||||
/* Ps */ "Open_Punctuation",
|
||||
];
|
||||
|
||||
const PUNCTUATION_REGEXP = new RegExp(
|
||||
`(?:${[
|
||||
new Charset(...asciiPunctuationCharacters).toRegExp().source,
|
||||
...unicodePunctuationClasses.map(
|
||||
(charset) => `\\p{General_Category=${charset}}`,
|
||||
),
|
||||
].join("|")})`,
|
||||
"u",
|
||||
);
|
||||
|
||||
// http://spec.commonmark.org/0.25/#punctuation-character
|
||||
const unicodePunctuationCharset = unicodeRegex({
|
||||
// http://unicode.org/Public/5.1.0/ucd/UCD.html#General_Category_Values
|
||||
General_Category: [
|
||||
/* Pc */ "Connector_Punctuation",
|
||||
/* Pd */ "Dash_Punctuation",
|
||||
/* Pe */ "Close_Punctuation",
|
||||
/* Pf */ "Final_Punctuation",
|
||||
/* Pi */ "Initial_Punctuation",
|
||||
/* Po */ "Other_Punctuation",
|
||||
/* Ps */ "Open_Punctuation",
|
||||
],
|
||||
});
|
||||
|
||||
const PUNCTUATION_REGEXP = new Charset(
|
||||
asciiPunctuationCharset,
|
||||
unicodePunctuationCharset,
|
||||
).toRegExp();
|
||||
|
||||
export { CJK_REGEXP, PUNCTUATION_REGEXP };
|
||||
@@ -95,7 +95,7 @@ function genericPrint(path, options, print) {
|
||||
`(^|${PUNCTUATION_REGEXP.source})(_+)`,
|
||||
`(_+)(${PUNCTUATION_REGEXP.source}|$)`,
|
||||
].join("|"),
|
||||
"g",
|
||||
"gu",
|
||||
),
|
||||
(_, text1, underscore1, underscore2, text2) =>
|
||||
(underscore1
|
||||
|
||||
@@ -7423,7 +7423,6 @@ __metadata:
|
||||
postcss-values-parser: "npm:2.0.1"
|
||||
prettier: "npm:3.3.2"
|
||||
pretty-bytes: "npm:6.1.1"
|
||||
regexp-util: "npm:2.0.0"
|
||||
remark-footnotes: "npm:2.0.0"
|
||||
remark-math: "npm:3.0.1"
|
||||
remark-parse: "npm:8.0.3"
|
||||
@@ -7631,7 +7630,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"regexp-util@npm:2.0.0, regexp-util@npm:^2.0.0":
|
||||
"regexp-util@npm:^2.0.0":
|
||||
version: 2.0.0
|
||||
resolution: "regexp-util@npm:2.0.0"
|
||||
dependencies:
|
||||
|
||||
Reference in new issue
Block a user