From ec8deb6c0baaa3eb17a7236f9c1cd9e1a8063c44 Mon Sep 17 00:00:00 2001 From: Ika Date: Sun, 5 Nov 2017 17:50:10 +0800 Subject: [PATCH] fix(markdown): print `---`-style thematic break (#3148) * fix(markdown): print `---`-style thematic break * test: fix diff --- src/printer-markdown.js | 4 +- .../markdown/__snapshots__/jsfmt.spec.js.snap | 12 +-- .../__snapshots__/jsfmt.spec.js.snap | 74 +++++++++++-------- tests/markdown_spec/example-11.md | 2 + tests/markdown_spec/example-15.md | 2 + tests/markdown_spec/example-46.md | 2 + .../__snapshots__/jsfmt.spec.js.snap | 6 +- 7 files changed, 60 insertions(+), 42 deletions(-) diff --git a/src/printer-markdown.js b/src/printer-markdown.js index 9fe2b0bc3..8befa327e 100644 --- a/src/printer-markdown.js +++ b/src/printer-markdown.js @@ -218,13 +218,13 @@ function genericPrint(path, options, print) { case "thematicBreak": { const counter = getAncestorCounter(path, "list"); if (counter === -1) { - return "- - -"; + return "---"; } const nthSiblingIndex = getNthListSiblingIndex( path.getParentNode(counter), path.getParentNode(counter + 1) ); - return nthSiblingIndex % 2 === 0 ? "- - -" : "* * *"; + return nthSiblingIndex % 2 === 0 ? "---" : "***"; } case "linkReference": return concat([ diff --git a/tests/markdown/__snapshots__/jsfmt.spec.js.snap b/tests/markdown/__snapshots__/jsfmt.spec.js.snap index 06a9ab732..93bf81b33 100644 --- a/tests/markdown/__snapshots__/jsfmt.spec.js.snap +++ b/tests/markdown/__snapshots__/jsfmt.spec.js.snap @@ -981,7 +981,7 @@ post](http://jlongster.com/A-Prettier-Formatter)) -- - - +--- ## What does Prettier do? @@ -2303,15 +2303,15 @@ Paragraph: Code -- - - +--- -- - - +--- -- - - +--- -- - - +--- -- - - +--- * * * diff --git a/tests/markdown_spec/__snapshots__/jsfmt.spec.js.snap b/tests/markdown_spec/__snapshots__/jsfmt.spec.js.snap index ff0403ae7..bfce3e861 100644 --- a/tests/markdown_spec/__snapshots__/jsfmt.spec.js.snap +++ b/tests/markdown_spec/__snapshots__/jsfmt.spec.js.snap @@ -88,15 +88,19 @@ exports[`example-10.md 1`] = ` `; exports[`example-11.md 1`] = ` + + *** --- ___ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- - - + -- - - +--- -- - - +--- + +--- `; @@ -124,15 +128,19 @@ __ `; exports[`example-15.md 1`] = ` + + *** *** *** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- - - + -- - - +--- -- - - +--- + +--- `; @@ -154,35 +162,35 @@ Foo \\**\\* exports[`example-18.md 1`] = ` _____________________________________ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- - - +--- `; exports[`example-19.md 1`] = ` - - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- - - +--- `; exports[`example-20.md 1`] = ` ** * ** * ** * ** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- - - +--- `; exports[`example-21.md 1`] = ` - - - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- - - +--- `; exports[`example-22.md 1`] = ` - - - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- - - +--- `; @@ -208,7 +216,7 @@ exports[`example-25.md 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * foo -- - - +--- * bar @@ -221,7 +229,7 @@ bar ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Foo -- - - +--- bar @@ -245,7 +253,7 @@ exports[`example-28.md 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Foo -- - - +--- * Bar @@ -256,7 +264,7 @@ exports[`example-29.md 1`] = ` - * * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Foo -* - - - +* --- `; @@ -411,15 +419,19 @@ exports[`example-45.md 1`] = ` `; exports[`example-46.md 1`] = ` + + **** ## foo **** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- - - + + +--- ## foo -- - - +--- `; @@ -514,7 +526,7 @@ exports[`example-53.md 1`] = ` Foo -- - - +--- `; @@ -524,7 +536,7 @@ Foo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Foo -- - - +--- `; @@ -547,7 +559,7 @@ Foo = = Foo -- - - +--- `; @@ -592,7 +604,7 @@ exports[`example-60.md 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Foo -- - - +--- `; @@ -613,7 +625,7 @@ exports[`example-62.md 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Foo -- - - +--- `; @@ -624,7 +636,7 @@ Bar ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Foo Bar -- - - +--- `; @@ -670,7 +682,7 @@ exports[`example-67.md 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * foo -- - - +--- `; @@ -680,7 +692,7 @@ exports[`example-68.md 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ foo -- - - +--- `; @@ -690,7 +702,7 @@ exports[`example-69.md 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > foo -- - - +--- `; @@ -727,7 +739,7 @@ baz ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Foo bar -- - - +--- baz @@ -741,7 +753,7 @@ baz ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Foo bar -- - - +--- baz @@ -865,7 +877,7 @@ Heading foo -- - - +--- `; @@ -2191,7 +2203,7 @@ exports[`example-194.md 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > foo -- - - +--- `; @@ -2312,7 +2324,7 @@ exports[`example-206.md 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > aaa -- - - +--- > bbb diff --git a/tests/markdown_spec/example-11.md b/tests/markdown_spec/example-11.md index 9d66e7d83..22ff355ce 100644 --- a/tests/markdown_spec/example-11.md +++ b/tests/markdown_spec/example-11.md @@ -1,3 +1,5 @@ + + *** --- ___ diff --git a/tests/markdown_spec/example-15.md b/tests/markdown_spec/example-15.md index 9adf3bafa..0af99d3ba 100644 --- a/tests/markdown_spec/example-15.md +++ b/tests/markdown_spec/example-15.md @@ -1,3 +1,5 @@ + + *** *** *** diff --git a/tests/markdown_spec/example-46.md b/tests/markdown_spec/example-46.md index be92151b2..89c228412 100644 --- a/tests/markdown_spec/example-46.md +++ b/tests/markdown_spec/example-46.md @@ -1,3 +1,5 @@ + + **** ## foo **** diff --git a/tests/markdown_thematicBreak/__snapshots__/jsfmt.spec.js.snap b/tests/markdown_thematicBreak/__snapshots__/jsfmt.spec.js.snap index 43f145f10..9352a8174 100644 --- a/tests/markdown_thematicBreak/__snapshots__/jsfmt.spec.js.snap +++ b/tests/markdown_thematicBreak/__snapshots__/jsfmt.spec.js.snap @@ -4,15 +4,15 @@ exports[`list.md 1`] = ` - * * * + - - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -* - - - +* --- -- * * * +- *** `; exports[`simple.md 1`] = ` *** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- - - +--- `;