Skip to content

Commit 03cf85f

Browse files
committed
preserve white space in attribute values in htmls in paragraph
1 parent 1b402c6 commit 03cf85f

4 files changed

Lines changed: 33 additions & 10 deletions

File tree

src/language-markdown/parse/micromark/html-flow-hack.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ To enforce all html tags parse like `<div>`
44
https://github.com/remarkjs/remark-gfm/issues/81
55
*/
66
import { fromMarkdown as originalFromMarkdown } from "mdast-util-from-markdown";
7+
import { htmlFlow } from "micromark-core-commonmark";
78
import { htmlBlockNames, htmlRawNames } from "micromark-util-html-tag-name";
9+
import { codes } from "micromark-util-symbol";
810
import * as assert from "#universal/assert";
911

1012
const isProduction = process.env.NODE_ENV !== "production";
@@ -48,4 +50,16 @@ if (isProduction) {
4850
};
4951
}
5052

51-
export { fromMarkdown };
53+
// interrupt html-text by html-flow to hack html tags in paragraphs
54+
function htmlFlowHackSyntax() {
55+
return {
56+
text: {
57+
[codes.lessThan]: {
58+
...htmlFlow,
59+
add: "before",
60+
},
61+
},
62+
};
63+
}
64+
65+
export { fromMarkdown, htmlFlowHackSyntax };

src/language-markdown/parse/parse-markdown.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { gfm as gfmSyntax } from "micromark-extension-gfm";
44
import { math as mathSyntax } from "micromark-extension-math";
55
import { syntax as wikiLinkSyntax } from "micromark-extension-wiki-link";
66
import parseFrontMatter from "../../main/front-matter/parse.js";
7-
import { fromMarkdown } from "./micromark/html-flow-hack.js";
7+
import {
8+
fromMarkdown,
9+
htmlFlowHackSyntax,
10+
} from "./micromark/html-flow-hack.js";
811
import { gfmFromMarkdown } from "./micromark/mdast-util-gfm.js";
912
import {
1013
liquidFromMarkdown,
@@ -14,7 +17,13 @@ import {
1417
let markdownParseOptions;
1518
function getMarkdownParseOptions() {
1619
return (markdownParseOptions ??= {
17-
extensions: [gfmSyntax(), mathSyntax(), wikiLinkSyntax(), liquidSyntax()],
20+
extensions: [
21+
gfmSyntax(),
22+
mathSyntax(),
23+
wikiLinkSyntax(),
24+
liquidSyntax(),
25+
htmlFlowHackSyntax(),
26+
],
1827
mdastExtensions: [
1928
gfmFromMarkdown(),
2029
mathFromMarkdown(),

tests/format/markdown/html/__snapshots__/format.test.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ text <a class="line 1
530530
> "></div>
531531
532532
text <a class="line 1
533-
line 2
533+
line 2
534534
" href="#">text</a> text
535535
536536
================================================================================
@@ -608,7 +608,7 @@ text <a class="line 1
608608
> "></div>
609609
610610
text <a class="line 1
611-
line 2
611+
line 2
612612
" href="#">text</a> text
613613
614614
================================================================================
@@ -686,7 +686,7 @@ text <a class="line 1
686686
> "></div>
687687
688688
text <a class="line 1
689-
line 2
689+
line 2
690690
" href="#">text</a> text
691691
692692
================================================================================

tests/format/markdown/link/__snapshots__/format.test.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ singleQuote: true
8080
![link](https://www.google.fr/foo-<bar)
8181
![link](https://www.google.fr/foo-%3Cbar) [link]:
8282
https://www.google.fr/()foo->bar [link]: https://www.google.fr/foo->bar [link]:
83-
https://www.google.fr/foo-%3Ebar [link]: https://www.google.fr/foo-<bar [link]:
84-
https://www.google.fr/foo-%3Cbar
83+
https://www.google.fr/foo-%3Ebar [link]: https://www.google.fr/foo-<bar
84+
[link]: https://www.google.fr/foo-%3Cbar
8585
8686
================================================================================
8787
`;
@@ -118,8 +118,8 @@ proseWrap: "always"
118118
![link](https://www.google.fr/foo-<bar)
119119
![link](https://www.google.fr/foo-%3Cbar) [link]:
120120
https://www.google.fr/()foo->bar [link]: https://www.google.fr/foo->bar [link]:
121-
https://www.google.fr/foo-%3Ebar [link]: https://www.google.fr/foo-<bar [link]:
122-
https://www.google.fr/foo-%3Cbar
121+
https://www.google.fr/foo-%3Ebar [link]: https://www.google.fr/foo-<bar
122+
[link]: https://www.google.fr/foo-%3Cbar
123123
124124
================================================================================
125125
`;

0 commit comments

Comments
 (0)