refactor(markdown): simplify regex (#3194)

* refactor(markdown): simplify regex

* fix: check exact string for heading
This commit is contained in:
Ika authored and GitHub committed 2017-11-08 02:46:32 +08:00
1 parent e1b3a830c3
commit a1e3181340
1 file changed
+6 -6
+6 -6
View File
@@ -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") ? "*" : "_";