fix(multiparser): fix markdown error and remove trailing new line (#3293)

This commit is contained in:
Ika authored and GitHub committed 2017-11-21 00:19:49 +08:00
1 parent b6f126eb29
commit 3cbbac3d08
5 files changed
+18 -8

No files matched your search

+2 -1
View File
@@ -236,7 +236,8 @@ function massageAST(ast, parent) {
(ast.tag.name === "gql" ||
ast.tag.name === "graphql" ||
ast.tag.name === "css" ||
ast.tag.name === "md")) ||
ast.tag.name === "md" ||
ast.tag.name === "markdown")) ||
ast.tag.type === "CallExpression")
) {
newObj.quasi.quasis.forEach(quasi => delete quasi.value);
+2 -1
View File
@@ -180,7 +180,8 @@ function fromBabylonFlowOrTypeScript(path) {
}
function dedent(str) {
const spaces = str.match(/\n^( *)/m)[1].length;
const firstMatchedIndent = str.match(/\n^( *)/m);
const spaces = firstMatchedIndent === null ? 0 : firstMatchedIndent[1].length;
return str.replace(new RegExp(`^ {${spaces}}`, "gm"), "").trim();
}
+4 -3
View File
@@ -66,9 +66,10 @@ function genericPrint(path, options, print) {
switch (node.type) {
case "root":
return normalizeDoc(
concat([printChildren(path, options, print), hardline])
);
return concat([
normalizeDoc(printChildren(path, options, print)),
hardline
]);
case "paragraph":
return printChildren(path, options, print, {
postprocessor: fill
@@ -17,10 +17,8 @@ md\`
~~~js
console.log("hi");
~~~
\\\`;
~~~
\`;
`;
@@ -73,8 +71,16 @@ export default function ReadMe() {
because he has a million decisions to make and he didn't want to be
bothered to make trivial ones like picking out clothes. I think Prettier
is like that.”
\`;
}
`;
exports[`single-line.js 1`] = `
markdown\`# hello\`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
markdown\`
# hello
\`;
`;
@@ -0,0 +1 @@
markdown`# hello`