Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(markdown): preserve non-breakable whitespaces #3327

Merged
merged 1 commit into from
Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,7 @@ function splitText(text) {

text
.replace(new RegExp(`(${cjkPattern})\n(${cjkPattern})`, "g"), "$1$2")
// `\s` but exclude full-width whitspace (`\u3000`)
.split(/([^\S\u3000]+)/)
.split(/([ \t\n]+)/)
.forEach((token, index, tokens) => {
// whitespace
if (index % 2 === 1) {
Expand Down
39 changes: 39 additions & 0 deletions tests/markdown_paragraph/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,42 @@ abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc
* [valid-expect](/packages/eslint-plugin-jest/docs/rules/valid-expect.md) - ensure expect is called correctly.

`;

exports[`whitespace.md 1`] = `
<!-- 0xA0 non-breaking whitespace -->

keep these words together keep these words together keep these words together keep these words together

<!-- 0x20 standard whitespace -->

keep these words together keep these words together keep these words together keep these words together
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<!-- 0xA0 non-breaking whitespace -->

keep these words together keep these words together keep these words together keep these words together

<!-- 0x20 standard whitespace -->

keep these words together keep these words together keep these words together
keep these words together

`;

exports[`whitespace.md 2`] = `
<!-- 0xA0 non-breaking whitespace -->

keep these words together keep these words together keep these words together keep these words together

<!-- 0x20 standard whitespace -->

keep these words together keep these words together keep these words together keep these words together
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<!-- 0xA0 non-breaking whitespace -->

keep these words together keep these words together keep these words together keep these words together

<!-- 0x20 standard whitespace -->

keep these words together keep these words together keep these words together keep these words together

`;
7 changes: 7 additions & 0 deletions tests/markdown_paragraph/whitespace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- 0xA0 non-breaking whitespace -->

keep these words together keep these words together keep these words together keep these words together

<!-- 0x20 standard whitespace -->

keep these words together keep these words together keep these words together keep these words together
2 changes: 1 addition & 1 deletion tests/markdown_spec/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3635,7 +3635,7 @@ a*"foo"*
exports[`example-328.md 1`] = `
* a *
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_ a _
_ a _

`;

Expand Down