From d5a3abd7a6668039b31122398d2117307b573b59 Mon Sep 17 00:00:00 2001 From: Ika Date: Wed, 22 Nov 2017 00:01:59 +0800 Subject: [PATCH] fix(markdown): only indent the first non-list node in checkbox list item (#3297) * fix(markdown): do not indent checkbox * fix: keep alignment for first non-list node * fix: force whitespaces --- src/printer-markdown.js | 7 +++- .../__snapshots__/jsfmt.spec.js.snap | 33 +++++++++++++++++++ tests/markdown_list/nested-checkbox.md | 11 +++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tests/markdown_list/nested-checkbox.md diff --git a/src/printer-markdown.js b/src/printer-markdown.js index 0af677e0..8ab137d4 100644 --- a/src/printer-markdown.js +++ b/src/printer-markdown.js @@ -249,7 +249,12 @@ function genericPrint(path, options, print) { node.checked === null ? "" : node.checked ? "[x] " : "[ ] "; return concat([ prefix, - align(" ".repeat(prefix.length), printChildren(path, options, print)) + printChildren(path, options, print, { + processor: (childPath, index) => + index === 0 && childPath.getValue().type !== "list" + ? align(" ".repeat(prefix.length), childPath.call(print)) + : childPath.call(print) + }) ]); } case "thematicBreak": { diff --git a/tests/markdown_list/__snapshots__/jsfmt.spec.js.snap b/tests/markdown_list/__snapshots__/jsfmt.spec.js.snap index d2a582b4..5d48d30a 100644 --- a/tests/markdown_list/__snapshots__/jsfmt.spec.js.snap +++ b/tests/markdown_list/__snapshots__/jsfmt.spec.js.snap @@ -77,6 +77,39 @@ exports[`nested.md 1`] = ` `; +exports[`nested-checkbox.md 1`] = ` +* parent list item parent list item parent list item parent list item parent list item parent list item + + * child list item child list item child list item child list item child list item child list item + + paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph + +* [x] parent task list item parent task list item parent task list item parent task list item + + * [x] child task list item child task list item child task list item child task list item + + paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* parent list item parent list item parent list item parent list item parent + list item parent list item + + * child list item child list item child list item child list item child list + item child list item + + paragraph paragraph paragraph paragraph paragraph paragraph paragraph + paragraph paragraph + +* [x] parent task list item parent task list item parent task list item parent + task list item + + * [x] child task list item child task list item child task list item child + task list item + + paragraph paragraph paragraph paragraph paragraph paragraph paragraph + paragraph paragraph + +`; + exports[`ordered.md 1`] = ` 1. 123 1. 456 diff --git a/tests/markdown_list/nested-checkbox.md b/tests/markdown_list/nested-checkbox.md new file mode 100644 index 00000000..f98995d1 --- /dev/null +++ b/tests/markdown_list/nested-checkbox.md @@ -0,0 +1,11 @@ +* parent list item parent list item parent list item parent list item parent list item parent list item + + * child list item child list item child list item child list item child list item child list item + + paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph + +* [x] parent task list item parent task list item parent task list item parent task list item + + * [x] child task list item child task list item child task list item child task list item + + paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph