Skip to content

Commit 7fb8e3f

Browse files
ikatyangazz
authored andcommitted
fix(markdown): no break on link (#3204)
* fix(markdown): link/image url head is breakable * fix(markdown): no break on link
1 parent 8f58ca0 commit 7fb8e3f

5 files changed

Lines changed: 39 additions & 32 deletions

File tree

src/printer-markdown.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ const asciiPunctuationPattern = escapeStringRegexp(
1818
"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
1919
);
2020

21-
const SINGLE_LINE_NODE_TYPES = ["heading", "tableCell", "footnoteDefinition"];
21+
const SINGLE_LINE_NODE_TYPES = [
22+
"heading",
23+
"tableCell",
24+
"footnoteDefinition",
25+
"link"
26+
];
2227

2328
const SIBLING_NODE_TYPES = ["listItem", "definition", "footnoteDefinition"];
2429

tests/markdown/__snapshots__/jsfmt.spec.js.snap

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,8 @@ Prettier is an opinionated code formatter with support for:
919919
* [GraphQL](http://graphql.org/)
920920
921921
It removes all original styling[\\*](#styling-footnote) and ensures that all
922-
outputted code conforms to a consistent style. (See this [blog
923-
post](http://jlongster.com/A-Prettier-Formatter))
922+
outputted code conforms to a consistent style. (See this
923+
[blog post](http://jlongster.com/A-Prettier-Formatter))
924924
925925
<details>
926926
<summary><strong>Table of Contents</strong></summary>
@@ -931,15 +931,13 @@ post](http://jlongster.com/A-Prettier-Formatter))
931931
932932
* [What does Prettier do?](#what-does-prettier-do)
933933
* [Why Prettier?](#why-prettier)
934-
* [Building and enforcing a style
935-
guide](#building-and-enforcing-a-style-guide)
934+
* [Building and enforcing a style guide](#building-and-enforcing-a-style-guide)
936935
* [Helping Newcomers](#helping-newcomers)
937936
* [Writing code](#writing-code)
938937
* [Easy to adopt](#easy-to-adopt)
939938
* [Clean up an existing codebase](#clean-up-an-existing-codebase)
940939
* [Ride the hype train](#ride-the-hype-train)
941-
* [How does it compare to ESLint (or TSLint,
942-
stylelint...)?](#how-does-it-compare-to-eslint-or-tslint-stylelint)
940+
* [How does it compare to ESLint (or TSLint, stylelint...)?](#how-does-it-compare-to-eslint-or-tslint-stylelint)
943941
* [Usage](#usage)
944942
* [CLI](#cli)
945943
* [ESLint](#eslint)
@@ -969,8 +967,7 @@ post](http://jlongster.com/A-Prettier-Formatter))
969967
* [Visual Studio Code](#visual-studio-code)
970968
* [Visual Studio](#visual-studio)
971969
* [Sublime Text](#sublime-text)
972-
* [JetBrains WebStorm, PHPStorm,
973-
PyCharm...](#jetbrains-webstorm-phpstorm-pycharm)
970+
* [JetBrains WebStorm, PHPStorm, PyCharm...](#jetbrains-webstorm-phpstorm-pycharm)
974971
* [Language Support](#language-support)
975972
* [Related Projects](#related-projects)
976973
* [Technical Details](#technical-details)
@@ -1220,9 +1217,8 @@ prettier --single-quote --trailing-comma es5 --write "{app,__{tests,mocks}__}/**
12201217
\`\`\`
12211218
12221219
Don't forget the quotes around the globs! The quotes make sure that Prettier
1223-
expands the globs rather than your shell, for cross-platform usage. The [glob
1224-
syntax from the glob
1225-
module](https://github.com/isaacs/node-glob/blob/master/README.md#glob-primer)
1220+
expands the globs rather than your shell, for cross-platform usage. The
1221+
[glob syntax from the glob module](https://github.com/isaacs/node-glob/blob/master/README.md#glob-primer)
12261222
is used.
12271223
12281224
#### \`--debug-check\`
@@ -1780,8 +1776,8 @@ parser: flow
17801776
17811777
### Configuration Overrides
17821778
1783-
Prettier borrows eslint's [override
1784-
format](http://eslint.org/docs/user-guide/configuring#example-configuration).
1779+
Prettier borrows eslint's
1780+
[override format](http://eslint.org/docs/user-guide/configuring#example-configuration).
17851781
This allows you to apply configuration to specific files.
17861782
17871783
JSON:
@@ -1845,8 +1841,8 @@ Atom users can simply install the
18451841
18461842
### Emacs
18471843
1848-
Emacs users should see [this
1849-
repository](https://github.com/prettier/prettier-emacs) for on-demand
1844+
Emacs users should see
1845+
[this repository](https://github.com/prettier/prettier-emacs) for on-demand
18501846
formatting.
18511847
18521848
### Vim
@@ -1855,8 +1851,8 @@ Vim users can simply install either
18551851
[sbdchd](https://github.com/sbdchd)/[neoformat](https://github.com/sbdchd/neoformat),
18561852
[w0rp](https://github.com/w0rp)/[ale](https://github.com/w0rp/ale), or
18571853
[prettier](https://github.com/prettier)/[vim-prettier](https://github.com/prettier/vim-prettier),
1858-
for more details see [this
1859-
directory](https://github.com/prettier/prettier/tree/master/editors/vim).
1854+
for more details see
1855+
[this directory](https://github.com/prettier/prettier/tree/master/editors/vim).
18601856
18611857
### Visual Studio Code
18621858
@@ -1865,13 +1861,12 @@ formatter\`.
18651861
18661862
Can also be installed using \`ext install prettier-vscode\`.
18671863
1868-
[Check its repository for configuration and
1869-
shortcuts](https://github.com/prettier/prettier-vscode)
1864+
[Check its repository for configuration and shortcuts](https://github.com/prettier/prettier-vscode)
18701865
18711866
### Visual Studio
18721867
1873-
Install the [JavaScript Prettier
1874-
extension](https://github.com/madskristensen/JavaScriptPrettier).
1868+
Install the
1869+
[JavaScript Prettier extension](https://github.com/madskristensen/JavaScriptPrettier).
18751870
18761871
### Sublime Text
18771872
@@ -1880,8 +1875,8 @@ Sublime Text support is available through Package Control and the
18801875
18811876
### JetBrains WebStorm, PHPStorm, PyCharm...
18821877
1883-
See the [WebStorm
1884-
guide](https://github.com/jlongster/prettier/tree/master/editors/webstorm/README.md).
1878+
See the
1879+
[WebStorm guide](https://github.com/jlongster/prettier/tree/master/editors/webstorm/README.md).
18851880
18861881
## Language Support
18871882
@@ -1933,8 +1928,8 @@ ability to have leading \`|\` for type definitions which prettier outputs.
19331928
* [\`markdown-magic-prettier\`](https://github.com/camacho/markdown-magic-prettier)
19341929
allows you to use Prettier to format JS
19351930
[codeblocks](https://help.github.com/articles/creating-and-highlighting-code-blocks/)
1936-
in Markdown files via [Markdown
1937-
Magic](https://github.com/DavidWells/markdown-magic)
1931+
in Markdown files via
1932+
[Markdown Magic](https://github.com/DavidWells/markdown-magic)
19381933
* [\`tslint-plugin-prettier\`](https://github.com/ikatyang/tslint-plugin-prettier)
19391934
runs Prettier as a TSLint rule and reports differences as individual TSLint
19401935
issues
@@ -1944,8 +1939,8 @@ ability to have leading \`|\` for type definitions which prettier outputs.
19441939
## Technical Details
19451940
19461941
This printer is a fork of [recast](https://github.com/benjamn/recast)'s printer
1947-
with its algorithm replaced by the one described by Wadler in "[A prettier
1948-
printer](http://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf)".
1942+
with its algorithm replaced by the one described by Wadler in
1943+
"[A prettier printer](http://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf)".
19491944
There still may be leftover code from recast that needs to be cleaned up.
19501945
19511946
The basic idea is that the printer takes an AST and returns an intermediate
@@ -2179,8 +2174,7 @@ This paragraph has some \`code\` in it.
21792174
21802175
![Alt Text](http://placehold.it/200x50 "Image Title")
21812176
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2182-
[View raw
2183-
(TEST.md)](https://raw.github.com/adamschwartz/github-markdown-kitchen-sink/master/README.md)
2177+
[View raw (TEST.md)](https://raw.github.com/adamschwartz/github-markdown-kitchen-sink/master/README.md)
21842178
21852179
This is a paragraph.
21862180

tests/markdown_link/__snapshots__/jsfmt.spec.js.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ exports[`autolink.md 1`] = `
77
88
`;
99

10+
exports[`long.md 1`] = `
11+
[podium context](https://github.schibsted.io/finn/podium/tree/master/packages/podium-context)
12+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13+
[podium context](https://github.schibsted.io/finn/podium/tree/master/packages/podium-context)
14+
15+
`;
16+
1017
exports[`simple.md 1`] = `
1118
[hello](#world)
1219
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

tests/markdown_link/long.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[podium context](https://github.schibsted.io/finn/podium/tree/master/packages/podium-context)

tests/markdown_paragraph/__snapshots__/jsfmt.spec.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ exports[`inline-nodes.md 1`] = `
4545
It removes all original styling[*](#styling-footnote) and ensures that all outputted code conforms to a consistent style. (See this [blog post](http://jlongster.com/A-Prettier-Formatter))
4646
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4747
It removes all original styling[\\*](#styling-footnote) and ensures that all
48-
outputted code conforms to a consistent style. (See this [blog
49-
post](http://jlongster.com/A-Prettier-Formatter))
48+
outputted code conforms to a consistent style. (See this
49+
[blog post](http://jlongster.com/A-Prettier-Formatter))
5050
5151
`;
5252

0 commit comments

Comments
 (0)