Skip to content

Commit 064f77d

Browse files
committed
Narrow down the scope of normalizeDoc in markdown printer
1 parent 71067aa commit 064f77d

4 files changed

Lines changed: 112 additions & 78 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { fill } from "../document/builders.js";
2+
import { normalizeDoc } from "../document/utils.js";
3+
4+
/**
5+
* @typedef {import("../common/ast-path.js").default} AstPath
6+
* @typedef {import("../document/builders.js").Doc} Doc
7+
*/
8+
9+
/**
10+
* @param {AstPath} path
11+
* @param {*} options
12+
* @param {*} print
13+
* @returns {Doc}
14+
*/
15+
function printParagraph(path, options, print) {
16+
const parts = path.map(print, "children");
17+
return normalizeDoc(fill(parts));
18+
}
19+
20+
export { printParagraph };

src/language-markdown/printer-markdown.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import collapseWhiteSpace from "collapse-white-space";
33
import {
44
align,
55
breakParent,
6-
fill,
76
group,
87
hardline,
98
hardlineWithoutBreakParent,
@@ -16,7 +15,7 @@ import {
1615
softline,
1716
} from "../document/builders.js";
1817
import { printDocToString } from "../document/printer.js";
19-
import { normalizeDoc, replaceEndOfLine } from "../document/utils.js";
18+
import { cleanDoc, replaceEndOfLine } from "../document/utils.js";
2019
import getMaxContinuousCount from "../utils/get-max-continuous-count.js";
2120
import getMinNotPresentContinuousCount from "../utils/get-min-not-present-continuous-count.js";
2221
import getPreferredQuote from "../utils/get-preferred-quote.js";
@@ -28,6 +27,7 @@ import embed from "./embed.js";
2827
import getVisitorKeys from "./get-visitor-keys.js";
2928
import { locEnd, locStart } from "./loc.js";
3029
import { insertPragma } from "./pragma.js";
30+
import { printParagraph } from "./print-paragraph.js";
3131
import preprocess from "./print-preprocess.js";
3232
import { printWhitespace } from "./print-whitespace.js";
3333
import {
@@ -76,11 +76,9 @@ function genericPrint(path, options, print) {
7676
if (node.children.length === 0) {
7777
return "";
7878
}
79-
return [normalizeDoc(printRoot(path, options, print)), hardline];
79+
return [cleanDoc(printRoot(path, options, print)), hardline];
8080
case "paragraph":
81-
return printChildren(path, options, print, {
82-
postprocessor: fill,
83-
});
81+
return printParagraph(path, options, print);
8482
case "sentence":
8583
return printChildren(path, options, print);
8684
case "word": {

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

Lines changed: 80 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,9 @@ const createCredentialDefaultArgs = {
339339
timeout: 60000,
340340
challenge: new Uint8Array([
341341
// must be a cryptographically random number sent from a server
342-
0x8c, 0x0a, 0x26, 0xff, 0x22, 0x91, 0xc1, 0xe9, 0xb9, 0x4e, 0x2e, 0x17, 0x1a,
343-
0x98, 0x6a, 0x73, 0x71, 0x9d, 0x43, 0x48, 0xd5, 0xa7, 0x6a, 0x15, 0x7e, 0x38,
344-
0x94, 0x52, 0x77, 0x97, 0x0f, 0xef,
342+
0x8c, 0x0a, 0x26, 0xff, 0x22, 0x91, 0xc1, 0xe9, 0xb9, 0x4e, 0x2e, 0x17,
343+
0x1a, 0x98, 0x6a, 0x73, 0x71, 0x9d, 0x43, 0x48, 0xd5, 0xa7, 0x6a, 0x15,
344+
0x7e, 0x38, 0x94, 0x52, 0x77, 0x97, 0x0f, 0xef,
345345
]).buffer,
346346
},
347347
};
@@ -381,7 +381,8 @@ proseWrap: "always"
381381
105deg,
382382
rgb(255 255 255 / 20%) 39%,
383383
rgb(51 56 57 / 100%) 96%
384-
) center center / 400px 200px no-repeat,
384+
)
385+
center center / 400px 200px no-repeat,
385386
url(big-star.png) center no-repeat,
386387
rebeccapurple;
387388
}
@@ -415,7 +416,8 @@ background-image: linear-gradient(
415416
to bottom,
416417
rgb(255 255 0 / 50%),
417418
rgb(0 0 255 / 50%)
418-
), url("catfront.png");
419+
),
420+
url("catfront.png");
419421
\`\`\`
420422
421423
================================================================================
@@ -455,7 +457,8 @@ width: 400px;
455457
rgb(131 58 180 / 100%) 0%,
456458
rgb(253 29 29 / 60%) 60%,
457459
rgb(252 176 69 / 100%) 100%
458-
), radial-gradient(circle, rgb(255 255 255 / 100%) 0%, rgb(0 0 0 / 100%) 28%);
460+
),
461+
radial-gradient(circle, rgb(255 255 255 / 100%) 0%, rgb(0 0 0 / 100%) 28%);
459462
border: 20px dashed black;
460463
padding: 20px;
461464
width: 400px;
@@ -495,8 +498,8 @@ background-position:
495498
.multi-bg-example {
496499
width: 100%;
497500
height: 400px;
498-
background-image: url(firefox.png), url(bubbles.png), linear-gradient(to right, rgb(30
499-
75 115 / 100%), rgb(255 255 255 / 0%));
501+
background-image: url(firefox.png), url(bubbles.png),
502+
linear-gradient(to right, rgb(30 75 115 / 100%), rgb(255 255 255 / 0%));
500503
background-repeat: no-repeat, no-repeat, no-repeat;
501504
background-position:
502505
bottom right,
@@ -536,7 +539,8 @@ proseWrap: "always"
536539
217deg,
537540
rgb(255 0 0 / 80%),
538541
rgb(255 0 0 / 0%) 70.71%
539-
), linear-gradient(127deg, rgb(0 255 0 / 80%), rgb(0 255 0 / 0%) 70.71%),
542+
),
543+
linear-gradient(127deg, rgb(0 255 0 / 80%), rgb(0 255 0 / 0%) 70.71%),
540544
linear-gradient(336deg, rgb(0 0 255 / 80%), rgb(0 0 255 / 0%) 70.71%);
541545
}
542546
\`\`\`
@@ -595,7 +599,8 @@ proseWrap: "always"
595599
circle at 93.3% 75%,
596600
rgb(0 255 0 / 50%),
597601
rgb(0 255 0 / 0%) 70.71%
598-
) beige;
602+
)
603+
beige;
599604
border-radius: 50%;
600605
}
601606
\`\`\`
@@ -653,7 +658,8 @@ rgb(255 255 0 / 50%) 120px,
653658
rgb(75 0 130 / 50%) 240px,
654659
rgb(238 130 238 / 50%) 280px,
655660
rgb(255 0 0 / 50%) 300px
656-
), repeating-linear-gradient(
661+
),
662+
repeating-linear-gradient(
657663
-190deg,
658664
rgb(255 0 0 / 50%) 30px,
659665
rgb(255 153 0 / 50%) 60px,
@@ -663,8 +669,18 @@ rgb(255 255 0 / 50%) 120px,
663669
rgb(75 0 130 / 50%) 180px,
664670
rgb(238 130 238 / 50%) 210px,
665671
rgb(255 0 0 / 50%) 230px
666-
), repeating-linear-gradient(23deg, red 50px, orange 100px, yellow 150px, green
667-
200px, blue 250px, indigo 300px, violet 350px, red 370px);
672+
),
673+
repeating-linear-gradient(
674+
23deg,
675+
red 50px,
676+
orange 100px,
677+
yellow 150px,
678+
green 200px,
679+
blue 250px,
680+
indigo 300px,
681+
violet 350px,
682+
red 370px
683+
);
668684
}
669685
\`\`\`
670686
@@ -763,7 +779,8 @@ transparent 69px,
763779
transparent 116px,
764780
rgb(255 206 0 / 25%) 116px,
765781
rgb(255 206 0 / 25%) 166px
766-
), repeating-linear-gradient(
782+
),
783+
repeating-linear-gradient(
767784
0deg,
768785
transparent,
769786
transparent 50px,
@@ -777,15 +794,21 @@ transparent 69px,
777794
transparent 116px,
778795
rgb(255 206 0 / 25%) 116px,
779796
rgb(255 206 0 / 25%) 166px
780-
), repeating-linear-gradient(
797+
),
798+
repeating-linear-gradient(
781799
-45deg,
782800
transparent,
783801
transparent 5px,
784802
rgb(143 77 63 / 25%) 5px,
785803
rgb(143 77 63 / 25%) 10px
786-
), repeating-linear-gradient(45deg, transparent, transparent 5px, rgb(
787-
143 77 63 / 25%
788-
) 5px, rgb(143 77 63 / 25%) 10px);
804+
),
805+
repeating-linear-gradient(
806+
45deg,
807+
transparent,
808+
transparent 5px,
809+
rgb(143 77 63 / 25%) 5px,
810+
rgb(143 77 63 / 25%) 10px
811+
);
789812
790813
background: repeating-linear-gradient(
791814
90deg,
@@ -795,20 +818,26 @@ transparent 69px,
795818
rgb(255 127 0 / 25%) 63px 69px,
796819
transparent 69px 116px,
797820
rgb(255 206 0 / 25%) 116px 166px
798-
), repeating-linear-gradient(
821+
),
822+
repeating-linear-gradient(
799823
0deg,
800824
transparent 0 50px,
801825
rgb(255 127 0 / 25%) 50px 56px,
802826
transparent 56px 63px,
803827
rgb(255 127 0 / 25%) 63px 69px,
804828
transparent 69px 116px,
805829
rgb(255 206 0 / 25%) 116px 166px
806-
), repeating-linear-gradient(
830+
),
831+
repeating-linear-gradient(
807832
-45deg,
808833
transparent 0 5px,
809834
rgb(143 77 63 / 25%) 5px 10px
810-
), repeating-linear-gradient(45deg, transparent 0 5px, rgb(143 77 63 / 25%) 5px
811-
10px);
835+
),
836+
repeating-linear-gradient(
837+
45deg,
838+
transparent 0 5px,
839+
rgb(143 77 63 / 25%) 5px 10px
840+
);
812841
}
813842
\`\`\`
814843
@@ -845,7 +874,8 @@ div {
845874
#000 0.25turn 0.5turn,
846875
#fff 0.5turn 0.75turn,
847876
#000 0.75turn
848-
) top left / 25% 25% repeat;
877+
)
878+
top left / 25% 25% repeat;
849879
border: 1px solid;
850880
}
851881
\`\`\`
@@ -877,12 +907,10 @@ filter: none;
877907
=====================================output=====================================
878908
\`\`\`css
879909
img {
880-
filter: drop-shadow(2px 2px 0 hsl(300deg 100% 50%)) drop-shadow(
881-
-2px -2px 0 hsl(210deg 100% 50%)
882-
)
883-
drop-shadow(2px 2px 0 hsl(120deg 100% 50%)) drop-shadow(
884-
-2px -2px 0 hsl(30deg 100% 50%)
885-
);
910+
filter: drop-shadow(2px 2px 0 hsl(300deg 100% 50%))
911+
drop-shadow(-2px -2px 0 hsl(210deg 100% 50%))
912+
drop-shadow(2px 2px 0 hsl(120deg 100% 50%))
913+
drop-shadow(-2px -2px 0 hsl(30deg 100% 50%));
886914
}
887915
img + img {
888916
filter: none;
@@ -915,8 +943,8 @@ border: 1px solid blue;
915943
\`\`\`css
916944
#MDN-logo {
917945
border: 1px solid blue;
918-
filter: drop-shadow(5px 5px 0 red) hue-rotate(180deg) drop-shadow(5px 5px 0
919-
red);
946+
filter: drop-shadow(5px 5px 0 red) hue-rotate(180deg)
947+
drop-shadow(5px 5px 0 red);
920948
}
921949
\`\`\`
922950
@@ -953,7 +981,8 @@ font-style: normal;
953981
font-family: "HeydingsControlsRegular";
954982
src: url("fonts/heydings_controls-webfont.eot");
955983
src:
956-
url("fonts/heydings_controls-webfont.eot?#iefix") format("embedded-opentype"),
984+
url("fonts/heydings_controls-webfont.eot?#iefix")
985+
format("embedded-opentype"),
957986
url("fonts/heydings_controls-webfont.woff") format("woff"),
958987
url("fonts/heydings_controls-webfont.ttf") format("truetype");
959988
font-weight: normal;
@@ -991,7 +1020,8 @@ proseWrap: "always"
9911020
@font-face {
9921021
font-family: "Bungee Spice";
9931022
src:
994-
url("https://fonts.googleapis.com/css2?family=Bungee+Spice") tech(color-COLRv1),
1023+
url("https://fonts.googleapis.com/css2?family=Bungee+Spice")
1024+
tech(color-COLRv1),
9951025
url("Bungee-fallback.otf") format("opentype");
9961026
}
9971027
\`\`\`
@@ -1025,7 +1055,8 @@ grid-auto-columns: min-content max-content auto;
10251055
grid-auto-columns: 100px 150px 390px;
10261056
grid-auto-columns: 10% 33.3%;
10271057
grid-auto-columns: 0.5fr 3fr 1fr;
1028-
grid-auto-columns: minmax(100px, auto) minmax(max-content, 2fr) minmax(20%, 80vmax);
1058+
grid-auto-columns: minmax(100px, auto) minmax(max-content, 2fr)
1059+
minmax(20%, 80vmax);
10291060
grid-auto-columns: 100px minmax(100px, auto) 10% 0.5fr fit-content(400px);
10301061
\`\`\`
10311062
@@ -1053,10 +1084,10 @@ proseWrap: "always"
10531084
=====================================output=====================================
10541085
\`\`\`css
10551086
@import url("gridy.css") supports(display: grid) screen and (max-width: 400px);
1056-
@import url("flexy.css") supports(not (display: grid) and (display: flex)) screen
1057-
and (max-width: 400px);
1058-
@import url("whatever.css") supports((selector(h2 > p)) and
1059-
(font-tech(color-COLRv1)));
1087+
@import url("flexy.css") supports(not (display: grid) and (display: flex))
1088+
screen and (max-width: 400px);
1089+
@import url("whatever.css")
1090+
supports((selector(h2 > p)) and (font-tech(color-COLRv1)));
10601091
\`\`\`
10611092
10621093
================================================================================
@@ -1079,7 +1110,8 @@ mask-image: image(url(mask.png), skyblue), linear-gradi
10791110
=====================================output=====================================
10801111
\`\`\`css
10811112
/* Multiple values */
1082-
mask-image: image(url(mask.png), skyblue), linear-gradient(rgb(0 0 0 / 100%), transparent);
1113+
mask-image: image(url(mask.png), skyblue),
1114+
linear-gradient(rgb(0 0 0 / 100%), transparent);
10831115
\`\`\`
10841116
10851117
================================================================================
@@ -1107,10 +1139,8 @@ padding: env(safe-area-inset-top, 20px) env(safe-area-inset-right, 20px) env(
11071139
=====================================output=====================================
11081140
\`\`\`css
11091141
body {
1110-
padding: env(safe-area-inset-top, 20px) env(safe-area-inset-right, 20px) env(
1111-
safe-area-inset-bottom,
1112-
20px
1113-
) env(safe-area-inset-left, 20px);
1142+
padding: env(safe-area-inset-top, 20px) env(safe-area-inset-right, 20px)
1143+
env(safe-area-inset-bottom, 20px) env(safe-area-inset-left, 20px);
11141144
}
11151145
\`\`\`
11161146
@@ -1143,10 +1173,8 @@ p {
11431173
p {
11441174
width: 300px;
11451175
border: 2px solid red;
1146-
padding: env(safe-area-inset-top, 50px) env(safe-area-inset-right, 50px) env(
1147-
safe-area-inset-bottom,
1148-
50px
1149-
) env(SAFE-AREA-INSET-LEFT, 50px);
1176+
padding: env(safe-area-inset-top, 50px) env(safe-area-inset-right, 50px)
1177+
env(safe-area-inset-bottom, 50px) env(SAFE-AREA-INSET-LEFT, 50px);
11501178
}
11511179
\`\`\`
11521180
@@ -1188,24 +1216,8 @@ proseWrap: "always"
11881216
=====================================output=====================================
11891217
\`\`\`css
11901218
#example-element:focus {
1191-
transform: rotate3d(1, 1, 1, 30deg) matrix3d(
1192-
1,
1193-
0,
1194-
0,
1195-
0,
1196-
0,
1197-
1,
1198-
6,
1199-
0,
1200-
0,
1201-
0,
1202-
1,
1203-
0,
1204-
50,
1205-
100,
1206-
0,
1207-
1.1
1208-
);
1219+
transform: rotate3d(1, 1, 1, 30deg)
1220+
matrix3d(1, 0, 0, 0, 0, 1, 6, 0, 0, 0, 1, 0, 50, 100, 0, 1.1);
12091221
}
12101222
\`\`\`
12111223
@@ -1257,9 +1269,9 @@ U+0152-0153, U+02BB-02BC, U+02C6,
12571269
local("Montserrat Regular"),
12581270
local("Montserrat-Regular"),
12591271
url("fonts/montserrat-regular.woff2") format("woff2");
1260-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
1261-
U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193,
1262-
U+2212, U+2215, U+FEFF, U+FFFD;
1272+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
1273+
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212,
1274+
U+2215, U+FEFF, U+FFFD;
12631275
}
12641276
}
12651277
\`\`\`

0 commit comments

Comments
 (0)