Skip to content

Commit 44b0283

Browse files
committed
Fix html
1 parent caa0df7 commit 44b0283

9 files changed

Lines changed: 100 additions & 95 deletions

File tree

src/language-markdown/print-preprocess.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function preprocess(ast, options) {
88
ast = mergeContinuousTexts(ast);
99
ast = transformIndentedCodeblockAndMarkItsParentList(ast, options);
1010
ast = markAlignedList(ast, options);
11-
ast = splitTextIntoSentences(ast);
11+
ast = splitTextIntoSentences(ast, options);
1212
return ast;
1313
}
1414

@@ -63,27 +63,31 @@ function mergeContinuousTexts(ast) {
6363
);
6464
}
6565

66-
function splitTextIntoSentences(ast) {
66+
function splitTextIntoSentences(ast, options) {
6767
return mapAst(ast, (node, index, [parentNode]) => {
6868
if (node.type !== "text") {
6969
return node;
7070
}
7171

72-
let { value } = node;
72+
// remark 10 unescape html entries, we can't use node.value here
73+
let text = options.originalText.slice(
74+
node.position.start.offset,
75+
node.position.end.offset
76+
);
7377

7478
if (parentNode.type === "paragraph") {
7579
if (index === 0) {
76-
value = value.trimStart();
80+
text = text.trimStart();
7781
}
7882
if (index === parentNode.children.length - 1) {
79-
value = value.trimEnd();
83+
text = text.trimEnd();
8084
}
8185
}
8286

8387
return {
8488
type: "sentence",
8589
position: node.position,
86-
children: splitText(value),
90+
children: splitText(text),
8791
};
8892
});
8993
}

tests/format/js/multiparser-markdown/__snapshots__/jsfmt.spec.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ markdown\`
115115
markdown\`
116116
- \\\`
117117
- \\\\\\\`
118-
- \\ a
119-
- \\\\
118+
- \\\\ a
119+
- \\\\\\\\
120120
- \\$
121121
- \\u1234
122122
\`;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ proseWrap: "always"
186186
187187
=====================================output=====================================
188188
> This is a long long long long long long long long long long long long long
189-
> long long paragraph. This is a long long long long long long long long long
189+
> long long paragraph. > This is a long long long long long long long long long
190190
> long long long long long long paragraph.
191191
192192
================================================================================

tests/format/markdown/long-table/__snapshots__/jsfmt.spec.js.snap

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ proseWrap: "never"
2424
| Property | Description | Type | Default |
2525
| --- | --- | --- | --- |
2626
| bordered | Toggles rendering of the border around the list | boolean | false |
27-
| footer | List footer renderer | string|ReactNode | - |
27+
| footer | List footer renderer | string\\|ReactNode | - |
2828
| grid | The grid type of list. You can set grid to something like {gutter: 16, column: 4} | object | - |
29-
| header | List header renderer | string|ReactNode | - |
29+
| header | List header renderer | string\\|ReactNode | - |
3030
| itemLayout | The layout of list, default is \`horizontal\`, If a vertical list is desired, set the itemLayout property to \`vertical\` | string | - |
31-
| rowKey | Item's unique key, could be a string or function that returns a string | string|Function(record):string | \`key\` |
32-
| loading | Shows a loading indicator while the contents of the list are being fetched | boolean|[object](https://ant.design/components/spin-cn/#API) ([more](https://github.com/ant-design/ant-design/issues/8659)) | false |
33-
| loadMore | Shows a load more content | string|ReactNode | - |
31+
| rowKey | Item's unique key, could be a string or function that returns a string | string\\|Function(record):string | \`key\` |
32+
| loading | Shows a loading indicator while the contents of the list are being fetched | boolean\\|[object](https://ant.design/components/spin-cn/#API) ([more](https://github.com/ant-design/ant-design/issues/8659)) | false |
33+
| loadMore | Shows a load more content | string\\|ReactNode | - |
3434
| locale | i18n text including empty text | object | emptyText: 'No Data' <br> |
35-
| pagination | Pagination [config](https://ant.design/components/pagination/), hide it by setting it to false | boolean | object | false |
35+
| pagination | Pagination [config](https://ant.design/components/pagination/), hide it by setting it to false | boolean \\| object | false |
3636
| split | Toggles rendering of the split under the list item | boolean | true |
3737
3838
================================================================================
@@ -58,19 +58,19 @@ printWidth: 80
5858
| pagination | Pagination [config](https://ant.design/components/pagination/), hide it by setting it to false | boolean \\| object | false |
5959
| split | Toggles rendering of the split under the list item | boolean | true |
6060
=====================================output=====================================
61-
| Property | Description | Type | Default |
62-
| ---------- | --------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | ------------------------- |
63-
| bordered | Toggles rendering of the border around the list | boolean | false |
64-
| footer | List footer renderer | string|ReactNode | - |
65-
| grid | The grid type of list. You can set grid to something like {gutter: 16, column: 4} | object | - |
66-
| header | List header renderer | string|ReactNode | - |
67-
| itemLayout | The layout of list, default is \`horizontal\`, If a vertical list is desired, set the itemLayout property to \`vertical\` | string | - |
68-
| rowKey | Item's unique key, could be a string or function that returns a string | string|Function(record):string | \`key\` |
69-
| loading | Shows a loading indicator while the contents of the list are being fetched | boolean|[object](https://ant.design/components/spin-cn/#API) ([more](https://github.com/ant-design/ant-design/issues/8659)) | false |
70-
| loadMore | Shows a load more content | string|ReactNode | - |
71-
| locale | i18n text including empty text | object | emptyText: 'No Data' <br> |
72-
| pagination | Pagination [config](https://ant.design/components/pagination/), hide it by setting it to false | boolean | object | false |
73-
| split | Toggles rendering of the split under the list item | boolean | true |
61+
| Property | Description | Type | Default |
62+
| ---------- | --------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | ------------------------- |
63+
| bordered | Toggles rendering of the border around the list | boolean | false |
64+
| footer | List footer renderer | string\\|ReactNode | - |
65+
| grid | The grid type of list. You can set grid to something like {gutter: 16, column: 4} | object | - |
66+
| header | List header renderer | string\\|ReactNode | - |
67+
| itemLayout | The layout of list, default is \`horizontal\`, If a vertical list is desired, set the itemLayout property to \`vertical\` | string | - |
68+
| rowKey | Item's unique key, could be a string or function that returns a string | string\\|Function(record):string | \`key\` |
69+
| loading | Shows a loading indicator while the contents of the list are being fetched | boolean\\|[object](https://ant.design/components/spin-cn/#API) ([more](https://github.com/ant-design/ant-design/issues/8659)) | false |
70+
| loadMore | Shows a load more content | string\\|ReactNode | - |
71+
| locale | i18n text including empty text | object | emptyText: 'No Data' <br> |
72+
| pagination | Pagination [config](https://ant.design/components/pagination/), hide it by setting it to false | boolean \\| object | false |
73+
| split | Toggles rendering of the split under the list item | boolean | true |
7474
7575
================================================================================
7676
`;

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ Prettier is an opinionated code formatter with support for:
924924
- [JSON](http://json.org/)
925925
- [GraphQL](http://graphql.org/)
926926
927-
It removes all original styling[\\*](#styling-footnote) and ensures that all
927+
It removes all original styling[\\\\*](#styling-footnote) and ensures that all
928928
outputted code conforms to a consistent style. (See this
929929
[blog post](http://jlongster.com/A-Prettier-Formatter))
930930
@@ -1020,11 +1020,11 @@ foo(
10201020
10211021
Prettier enforces a consistent code **style** (i.e. code formatting that won't
10221022
affect the AST) across your entire codebase because it disregards the original
1023-
styling[\\*](#styling-footnote) by parsing it away and re-printing the parsed AST
1024-
with its own rules that take the maximum line length into account, wrapping code
1025-
when necessary.
1023+
styling[\\\\*](#styling-footnote) by parsing it away and re-printing the parsed
1024+
AST with its own rules that take the maximum line length into account, wrapping
1025+
code when necessary.
10261026
1027-
<a href="#styling-footnote" name="styling-footnote">\\*</a>_Well actually, some
1027+
<a href="#styling-footnote" name="styling-footnote">\\\\*</a>_Well actually, some
10281028
original styling is preserved when practical—see [empty lines] and [multi-line
10291029
objects]._
10301030
@@ -1201,8 +1201,8 @@ npm install --save-dev --save-exact prettier
12011201
npm install --global prettier
12021202
\`\`\`
12031203
1204-
> We recommend pinning an exact version of prettier in your \`package.json\` as we
1205-
> introduce stylistic changes in patch releases.
1204+
> We recommend pinning an exact version of prettier in your \`package.json\` > as
1205+
> we introduce stylistic changes in patch releases.
12061206
12071207
### CLI
12081208
@@ -1634,9 +1634,9 @@ Valid options:
16341634
This requires node 8 or a
16351635
[transform](https://babeljs.io/docs/plugins/syntax-trailing-function-commas/).
16361636
1637-
| Default | CLI Override | API Override |
1638-
| -------- | -------------------------------------------- | -------------------------------------------- |
1639-
| \`"none"\` | <code>--trailing-comma <none|es5|all></code> | <code>trailingComma: "<none|es5|all>"</code> |
1637+
| Default | CLI Override | API Override |
1638+
| -------- | ------------------------------------------------------ | ------------------------------------------------------ |
1639+
| \`"none"\` | <code>--trailing-comma <none&#124;es5&#124;all></code> | <code>trailingComma: "<none&#124;es5&#124;all>"</code> |
16401640
16411641
### Bracket Spacing
16421642
@@ -2901,7 +2901,7 @@ Prettier is an opinionated code formatter with support for:
29012901
- [JSON](http://json.org/)
29022902
- [GraphQL](http://graphql.org/)
29032903
2904-
It removes all original styling[\\*](#styling-footnote) and ensures that all
2904+
It removes all original styling[\\\\*](#styling-footnote) and ensures that all
29052905
outputted code conforms to a consistent style. (See this
29062906
[blog post](http://jlongster.com/A-Prettier-Formatter))
29072907
@@ -2997,11 +2997,11 @@ foo(
29972997
29982998
Prettier enforces a consistent code **style** (i.e. code formatting that won't
29992999
affect the AST) across your entire codebase because it disregards the original
3000-
styling[\\*](#styling-footnote) by parsing it away and re-printing the parsed AST
3001-
with its own rules that take the maximum line length into account, wrapping code
3002-
when necessary.
3000+
styling[\\\\*](#styling-footnote) by parsing it away and re-printing the parsed
3001+
AST with its own rules that take the maximum line length into account, wrapping
3002+
code when necessary.
30033003
3004-
<a href="#styling-footnote" name="styling-footnote">\\*</a>_Well actually, some
3004+
<a href="#styling-footnote" name="styling-footnote">\\\\*</a>_Well actually, some
30053005
original styling is preserved when practical—see [empty lines] and [multi-line
30063006
objects]._
30073007
@@ -3178,8 +3178,8 @@ npm install --save-dev --save-exact prettier
31783178
npm install --global prettier
31793179
\`\`\`
31803180
3181-
> We recommend pinning an exact version of prettier in your \`package.json\` as we
3182-
> introduce stylistic changes in patch releases.
3181+
> We recommend pinning an exact version of prettier in your \`package.json\` > as
3182+
> we introduce stylistic changes in patch releases.
31833183
31843184
### CLI
31853185
@@ -3611,9 +3611,9 @@ Valid options:
36113611
This requires node 8 or a
36123612
[transform](https://babeljs.io/docs/plugins/syntax-trailing-function-commas/).
36133613
3614-
| Default | CLI Override | API Override |
3615-
| -------- | -------------------------------------------- | -------------------------------------------- |
3616-
| \`"none"\` | <code>--trailing-comma <none|es5|all></code> | <code>trailingComma: "<none|es5|all>"</code> |
3614+
| Default | CLI Override | API Override |
3615+
| -------- | ------------------------------------------------------ | ------------------------------------------------------ |
3616+
| \`"none"\` | <code>--trailing-comma <none&#124;es5&#124;all></code> | <code>trailingComma: "<none&#124;es5&#124;all>"</code> |
36173617
36183618
### Bracket Spacing
36193619

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ $
1919
2020
\\$
2121
22-
\\$
22+
\\\\$
2323
24-
\\$
24+
\\\\\\$
2525
2626
================================================================================
2727
`;
@@ -164,7 +164,7 @@ $\\alpha\\$
164164
165165
---
166166
167-
$\\alpha$
167+
\\$\\alpha\\$
168168
169169
---
170170
@@ -184,7 +184,7 @@ $\`\\alpha\`$
184184
185185
---
186186
187-
$\\alpha$$
187+
$\\alpha\\$$
188188
189189
---
190190

0 commit comments

Comments
 (0)