refactor(markdown): simplify regex (#3194)
* refactor(markdown): simplify regex * fix: check exact string for heading
This commit is contained in:
1 file changed
+6
-6
@@ -87,8 +87,8 @@ function genericPrint(path, options, print) {
|
||||
const index = parentNode.children.indexOf(node);
|
||||
const nextNode = parentNode.children[index + 1];
|
||||
|
||||
// special prefix that may cause different meaning
|
||||
if (nextNode && nextNode.value.match(/^(#{1,6}|>+)|^(-|\+|\*)$/)) {
|
||||
// leading char that may cause different syntax
|
||||
if (nextNode && /^>|^([-+*]|#{1,6})$/.test(nextNode.value)) {
|
||||
return node.value === "" ? "" : " ";
|
||||
}
|
||||
|
||||
@@ -104,15 +104,15 @@ function genericPrint(path, options, print) {
|
||||
prevNode.type === "sentence" &&
|
||||
prevNode.children.length > 0 &&
|
||||
prevNode.children[prevNode.children.length - 1].type === "word" &&
|
||||
prevNode.children[prevNode.children.length - 1].value.match(
|
||||
new RegExp(`[^${asciiPunctuationPattern}]$`)
|
||||
new RegExp(`[^${asciiPunctuationPattern}]$`).test(
|
||||
prevNode.children[prevNode.children.length - 1].value
|
||||
)) ||
|
||||
(nextNode &&
|
||||
nextNode.type === "sentence" &&
|
||||
nextNode.children.length > 0 &&
|
||||
nextNode.children[0].type === "word" &&
|
||||
nextNode.children[0].value.match(
|
||||
new RegExp(`^[^${asciiPunctuationPattern}]`)
|
||||
new RegExp(`^[^${asciiPunctuationPattern}]`).test(
|
||||
nextNode.children[0].value
|
||||
));
|
||||
const style =
|
||||
hasPrevOrNextWord || getAncestorNode(path, "emphasis") ? "*" : "_";
|
||||
|
||||
Reference in new issue
Block a user