diff --git a/src/printer-markdown.js b/src/printer-markdown.js index 71746487b..d9bcee338 100644 --- a/src/printer-markdown.js +++ b/src/printer-markdown.js @@ -158,7 +158,15 @@ function genericPrint(path, options, print) { printChildren(path, options, print) ]); case "code": { - if (/\s/.test(options.originalText[node.position.start.offset])) { + if ( + // the first char may point to `\n`, e.g. `\n\t\tbar`, just ignore it + /^\n?( {4,}|\t)/.test( + options.originalText.slice( + node.position.start.offset, + node.position.end.offset + ) + ) + ) { // indented code block return align( 4, diff --git a/tests/markdown_code/__snapshots__/jsfmt.spec.js.snap b/tests/markdown_code/__snapshots__/jsfmt.spec.js.snap index 933741428..64974b2fc 100644 --- a/tests/markdown_code/__snapshots__/jsfmt.spec.js.snap +++ b/tests/markdown_code/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,56 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`additional-space.md 1`] = ` +1. Fork the repo and create your branch from \`master\`. + + Open terminal (e.g. Terminal, iTerm, Git Bash or Git Shell) and type: + \`\`\`sh + git clone https://github.com//jest + cd jest + git checkout -b my_branch + \`\`\` + Note: + Replace \`\` with your GitHub username + +3. Run \`yarn install\`. + On Windows: + To install [Yarn](https://yarnpkg.com/en/docs/install#windows-tab) on Windows you may need to download either node.js or Chocolatey
+ + \`\`\`sh + yarn install + \`\`\` + To check your version of Yarn and ensure it's installed you can type: + \`\`\`sh + yarn --version + \`\`\`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +1. Fork the repo and create your branch from \`master\`. + + Open terminal (e.g. Terminal, iTerm, Git Bash or Git Shell) and type: + + \`\`\`sh + git clone https://github.com//jest + cd jest + git checkout -b my_branch + \`\`\` + + Note: Replace \`\` with your GitHub username + +2. Run \`yarn install\`. On Windows: To install + [Yarn](https://yarnpkg.com/en/docs/install#windows-tab) on Windows you may + need to download either node.js or Chocolatey
+ + \`\`\`sh + yarn install + \`\`\` + + To check your version of Yarn and ensure it's installed you can type: + + \`\`\`sh + yarn --version + \`\`\` + +`; + exports[`backtick.md 1`] = ` \`\`\`\`\`\`\`\`\`\` diff --git a/tests/markdown_code/additional-space.md b/tests/markdown_code/additional-space.md new file mode 100644 index 000000000..17d1f5d3e --- /dev/null +++ b/tests/markdown_code/additional-space.md @@ -0,0 +1,22 @@ +1. Fork the repo and create your branch from `master`. + + Open terminal (e.g. Terminal, iTerm, Git Bash or Git Shell) and type: + ```sh + git clone https://github.com//jest + cd jest + git checkout -b my_branch + ``` + Note: + Replace `` with your GitHub username + +3. Run `yarn install`. + On Windows: + To install [Yarn](https://yarnpkg.com/en/docs/install#windows-tab) on Windows you may need to download either node.js or Chocolatey
+ + ```sh + yarn install + ``` + To check your version of Yarn and ensure it's installed you can type: + ```sh + yarn --version + ``` \ No newline at end of file diff --git a/tests/markdown_spec/__snapshots__/jsfmt.spec.js.snap b/tests/markdown_spec/__snapshots__/jsfmt.spec.js.snap index bfce3e861..0abe52677 100644 --- a/tests/markdown_spec/__snapshots__/jsfmt.spec.js.snap +++ b/tests/markdown_spec/__snapshots__/jsfmt.spec.js.snap @@ -1049,8 +1049,10 @@ exports[`example-98.md 1`] = ` aaa \`\`\` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - aaa - aaa +\`\`\` +aaa +aaa +\`\`\` `; @@ -1061,9 +1063,11 @@ aaa aaa \`\`\` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - aaa - aaa - aaa +\`\`\` +aaa +aaa +aaa +\`\`\` `; @@ -1074,9 +1078,11 @@ exports[`example-100.md 1`] = ` aaa \`\`\` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - aaa - aaa - aaa +\`\`\` +aaa + aaa +aaa +\`\`\` `; @@ -1107,7 +1113,9 @@ exports[`example-103.md 1`] = ` aaa \`\`\` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - aaa +\`\`\` +aaa +\`\`\` `; @@ -2537,14 +2545,16 @@ bar bar - - baz +\`\`\`\` +- baz - + \`\`\` - foo ++ \`\`\` + foo - bar - \`\`\` + bar + \`\`\` +\`\`\`\` `;