refactor(markdown): use built-in ignore (#4274)

master
Ika 2018-04-07 00:19:26 +08:00 committed by GitHub
parent 18aaee594f
commit 01e8e2bb8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 16 deletions

View File

@ -38,7 +38,9 @@ const remark = {
get parse() {
return eval("require")("./parser-markdown");
},
astFormat: "mdast"
astFormat: "mdast",
locStart: node => node.position.start.offset,
locEnd: node => node.position.end.offset
};
const parsers = {

View File

@ -601,28 +601,15 @@ function printChildren(path, options, print, events) {
const node = path.getValue();
const parts = [];
let counter = 0;
let lastChildNode;
let prettierIgnore = false;
path.map((childPath, index) => {
const childNode = childPath.getValue();
const result = prettierIgnore
? options.originalText.slice(
childNode.position.start.offset,
childNode.position.end.offset
)
: processor(childPath, index);
prettierIgnore = false;
const result = processor(childPath, index);
if (result !== false) {
prettierIgnore = isPrettierIgnore(childNode) === "next";
const data = {
parts,
index: counter++,
prevNode: lastChildNode,
parentNode: node,
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 = {
print: genericPrint,
embed,
massageAstNode: clean,
hasPrettierIgnore: privateUtil.hasIgnoreComment
hasPrettierIgnore
};