diff --git a/src/doc-printer.js b/src/doc-printer.js index b1945f8fa..f33c2b30d 100644 --- a/src/doc-printer.js +++ b/src/doc-printer.js @@ -41,7 +41,7 @@ function makeAlign(ind, n) { indent: ind.indent, align: { spaces: ind.align.spaces + (typeof n === "number" ? " ".repeat(n) : n), - tabs: ind.align.tabs + (n ? "\t" : "") + tabs: ind.align.tabs + (typeof n === "number" ? (n ? "\t" : "") : n) } }; } diff --git a/src/printer-markdown.js b/src/printer-markdown.js index c16e3fd13..c2185ebbd 100644 --- a/src/printer-markdown.js +++ b/src/printer-markdown.js @@ -186,9 +186,10 @@ function genericPrint(path, options, print) { ) ) { // indented code block + const alignment = " ".repeat(4); return align( - 4, - concat([" ".repeat(4), join(hardline, node.value.split("\n"))]) + alignment, + concat([alignment, join(hardline, node.value.split("\n"))]) ); } @@ -239,7 +240,10 @@ function genericPrint(path, options, print) { : isGitDiffFriendlyOrderedList ? 1 : node.start + index) + (nthSiblingIndex % 2 === 0 ? ". " : ") ") : nthSiblingIndex % 2 === 0 ? "* " : "- "; - return concat([prefix, align(prefix.length, childPath.call(print))]); + return concat([ + prefix, + align(" ".repeat(prefix.length), childPath.call(print)) + ]); } }); } @@ -248,7 +252,7 @@ function genericPrint(path, options, print) { node.checked === null ? "" : node.checked ? "[x] " : "[ ] "; return concat([ prefix, - align(prefix.length, printChildren(path, options, print)) + align(" ".repeat(prefix.length), printChildren(path, options, print)) ]); } case "thematicBreak": { diff --git a/tests/markdown_indentation/__snapshots__/jsfmt.spec.js.snap b/tests/markdown_indentation/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..474f22d91 --- /dev/null +++ b/tests/markdown_indentation/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,18 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`example.md 1`] = ` +- Top level list item 1 +- Top level list item 2 + - Nested List item 1 + - Nested List item 2 + - Sub-Nested List item 1 + - Sub-Nested List item 2 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* Top level list item 1 +* Top level list item 2 + * Nested List item 1 + * Nested List item 2 + * Sub-Nested List item 1 + * Sub-Nested List item 2 + +`; diff --git a/tests/markdown_indentation/example.md b/tests/markdown_indentation/example.md new file mode 100644 index 000000000..09a8bb516 --- /dev/null +++ b/tests/markdown_indentation/example.md @@ -0,0 +1,6 @@ +- Top level list item 1 +- Top level list item 2 + - Nested List item 1 + - Nested List item 2 + - Sub-Nested List item 1 + - Sub-Nested List item 2 diff --git a/tests/markdown_indentation/jsfmt.spec.js b/tests/markdown_indentation/jsfmt.spec.js new file mode 100644 index 000000000..72f92f2ca --- /dev/null +++ b/tests/markdown_indentation/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, { parser: "markdown", useTabs: true });