refactor(markdown): use built-in ignore (#4274)
parent
18aaee594f
commit
01e8e2bb8a
|
@ -38,7 +38,9 @@ const remark = {
|
||||||
get parse() {
|
get parse() {
|
||||||
return eval("require")("./parser-markdown");
|
return eval("require")("./parser-markdown");
|
||||||
},
|
},
|
||||||
astFormat: "mdast"
|
astFormat: "mdast",
|
||||||
|
locStart: node => node.position.start.offset,
|
||||||
|
locEnd: node => node.position.end.offset
|
||||||
};
|
};
|
||||||
|
|
||||||
const parsers = {
|
const parsers = {
|
||||||
|
|
|
@ -601,28 +601,15 @@ function printChildren(path, options, print, events) {
|
||||||
const node = path.getValue();
|
const node = path.getValue();
|
||||||
const parts = [];
|
const parts = [];
|
||||||
|
|
||||||
let counter = 0;
|
|
||||||
let lastChildNode;
|
let lastChildNode;
|
||||||
let prettierIgnore = false;
|
|
||||||
|
|
||||||
path.map((childPath, index) => {
|
path.map((childPath, index) => {
|
||||||
const childNode = childPath.getValue();
|
const childNode = childPath.getValue();
|
||||||
|
|
||||||
const result = prettierIgnore
|
const result = processor(childPath, index);
|
||||||
? options.originalText.slice(
|
|
||||||
childNode.position.start.offset,
|
|
||||||
childNode.position.end.offset
|
|
||||||
)
|
|
||||||
: processor(childPath, index);
|
|
||||||
|
|
||||||
prettierIgnore = false;
|
|
||||||
|
|
||||||
if (result !== false) {
|
if (result !== false) {
|
||||||
prettierIgnore = isPrettierIgnore(childNode) === "next";
|
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
parts,
|
parts,
|
||||||
index: counter++,
|
|
||||||
prevNode: lastChildNode,
|
prevNode: lastChildNode,
|
||||||
parentNode: node,
|
parentNode: node,
|
||||||
options
|
options
|
||||||
|
@ -795,9 +782,20 @@ function clean(ast, newObj) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasPrettierIgnore(path) {
|
||||||
|
const index = +path.getName();
|
||||||
|
|
||||||
|
if (index === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const prevNode = path.getParentNode().children[index - 1];
|
||||||
|
return isPrettierIgnore(prevNode) === "next";
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
print: genericPrint,
|
print: genericPrint,
|
||||||
embed,
|
embed,
|
||||||
massageAstNode: clean,
|
massageAstNode: clean,
|
||||||
hasPrettierIgnore: privateUtil.hasIgnoreComment
|
hasPrettierIgnore
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue