fix(markdown): handle additional spaces before `code` (#3180)

* fix(markdown): handle additional spaces before `code`

* test: update snapshots

* fix: ignore leading `\n` from indented `code`

* docs: add comment
master
Ika 2017-11-07 19:25:20 +08:00 committed by Lucas Azzola
parent b099771e5f
commit ffd198beaa
4 changed files with 106 additions and 15 deletions

View File

@ -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,

View File

@ -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/<your_username>/jest
cd jest
git checkout -b my_branch
\`\`\`
Note:
Replace \`<your_username>\` 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<br />
\`\`\`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/<your_username>/jest
cd jest
git checkout -b my_branch
\`\`\`
Note: Replace \`<your_username>\` 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<br />
\`\`\`sh
yarn install
\`\`\`
To check your version of Yarn and ensure it's installed you can type:
\`\`\`sh
yarn --version
\`\`\`
`;
exports[`backtick.md 1`] = `
\`\`\`\`\`\`\`\`\`\`

View File

@ -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/<your_username>/jest
cd jest
git checkout -b my_branch
```
Note:
Replace `<your_username>` 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<br />
```sh
yarn install
```
To check your version of Yarn and ensure it's installed you can type:
```sh
yarn --version
```

View File

@ -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
\`\`\`
\`\`\`\`
`;