Skip to content

Commit 95a6116

Browse files
committed
fix: align mdp preview elements horizontally
- Change content width from 78ch to 42rem; ch units computed differently for heading vs body fonts, causing misalignment - Add div.sourceCode override to counter pandoc's margin reset that was preventing code block centering
1 parent 8b366c4 commit 95a6116

File tree

1 file changed

+183
-10
lines changed

1 file changed

+183
-10
lines changed

assets/mdp-preview.css

Lines changed: 183 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
--mdp-muted: #5e6c76;
77
--mdp-accent: #0f766e;
88
--mdp-code-bg: #ece3d7;
9+
--mdp-content-width: 42rem;
910
}
1011

1112
* {
@@ -24,11 +25,55 @@ body {
2425
font: 1.08rem/1.7 "Source Serif 4", Charter, "Iowan Old Style", Georgia, serif;
2526
}
2627

27-
body > * {
28-
margin-inline: auto;
29-
max-width: 78ch;
28+
/* Content width constraint - all block elements */
29+
body > header,
30+
body > h1,
31+
body > h2,
32+
body > h3,
33+
body > h4,
34+
body > h5,
35+
body > h6,
36+
body > p,
37+
body > ul,
38+
body > ol,
39+
body > dl,
40+
body > pre,
41+
body > blockquote,
42+
body > table,
43+
body > figure,
44+
body > hr,
45+
body > div,
46+
body > section,
47+
body > article {
48+
max-width: var(--mdp-content-width);
49+
margin-left: auto;
50+
margin-right: auto;
3051
}
3152

53+
/* Pandoc title block header */
54+
header#title-block-header {
55+
margin-bottom: 2rem;
56+
padding-bottom: 1rem;
57+
border-bottom: 1px solid var(--mdp-border);
58+
}
59+
60+
header#title-block-header h1 {
61+
margin-top: 0;
62+
}
63+
64+
header#title-block-header .subtitle {
65+
font-size: 1.15rem;
66+
color: var(--mdp-muted);
67+
margin-top: -0.5rem;
68+
}
69+
70+
header#title-block-header .author,
71+
header#title-block-header .date {
72+
color: var(--mdp-muted);
73+
font-size: 0.95rem;
74+
}
75+
76+
/* Headings */
3277
h1,
3378
h2,
3479
h3,
@@ -43,27 +88,31 @@ h6 {
4388
margin-bottom: 0.55em;
4489
}
4590

46-
h1,
47-
h2 {
48-
border-bottom: 1px solid var(--mdp-border);
49-
padding-bottom: 0.22em;
50-
}
5191

92+
/* Links */
5293
a {
5394
color: var(--mdp-accent);
5495
text-decoration-thickness: 0.09em;
5596
text-underline-offset: 0.18em;
5697
}
5798

99+
/* Code */
58100
code,
59101
kbd,
60102
samp {
61103
font-family: "Iosevka Term", "JetBrains Mono", "SFMono-Regular", monospace;
62104
font-size: 0.92em;
63105
}
64106

107+
:not(pre) > code {
108+
background: var(--mdp-code-bg);
109+
padding: 0.15em 0.35em;
110+
border-radius: 4px;
111+
}
112+
65113
pre {
66-
margin: 1.2rem 0;
114+
margin-top: 1.2rem;
115+
margin-bottom: 1.2rem;
67116
padding: 0.95rem 1rem;
68117
border: 1px solid var(--mdp-border);
69118
border-radius: 10px;
@@ -73,16 +122,62 @@ pre {
73122

74123
pre code {
75124
background: transparent;
125+
padding: 0;
126+
}
127+
128+
/* Pandoc wraps code blocks in div.sourceCode - override its margin reset */
129+
div.sourceCode {
130+
max-width: var(--mdp-content-width);
131+
margin-left: auto;
132+
margin-right: auto;
76133
}
77134

135+
/* Blockquotes */
78136
blockquote {
79-
margin: 1rem 0;
137+
margin-top: 1rem;
138+
margin-bottom: 1rem;
80139
padding: 0.2rem 0.95rem;
81140
border-left: 0.3rem solid var(--mdp-border);
82141
color: var(--mdp-muted);
83142
background: color-mix(in srgb, var(--mdp-surface) 75%, transparent);
84143
}
85144

145+
blockquote > * {
146+
max-width: none;
147+
}
148+
149+
/* Lists */
150+
ul,
151+
ol {
152+
padding-left: 1.5rem;
153+
}
154+
155+
li {
156+
margin: 0.3em 0;
157+
}
158+
159+
li > ul,
160+
li > ol {
161+
margin: 0.3em 0;
162+
}
163+
164+
dl {
165+
display: grid;
166+
grid-template-columns: auto 1fr;
167+
gap: 0.4rem 1rem;
168+
}
169+
170+
dt {
171+
font-weight: 600;
172+
grid-column: 1;
173+
}
174+
175+
dd {
176+
margin: 0;
177+
grid-column: 2;
178+
}
179+
180+
/* Tables */
86181
table {
87182
border-collapse: collapse;
88183
width: 100%;
@@ -92,6 +187,35 @@ th,
92187
td {
93188
border: 1px solid var(--mdp-border);
94189
padding: 0.5rem 0.6rem;
190+
text-align: left;
191+
}
192+
193+
th {
194+
background: var(--mdp-surface);
195+
font-weight: 600;
196+
}
197+
198+
tr:nth-child(even) {
199+
background: color-mix(in srgb, var(--mdp-surface) 50%, transparent);
200+
}
201+
202+
/* Figures and images */
203+
figure {
204+
margin-top: 1.3rem;
205+
margin-bottom: 1.3rem;
206+
}
207+
208+
figure > img,
209+
figure > svg {
210+
margin: 0 auto;
211+
}
212+
213+
figcaption {
214+
margin-top: 0.5rem;
215+
text-align: center;
216+
font-size: 0.9rem;
217+
color: var(--mdp-muted);
218+
font-style: italic;
95219
}
96220

97221
img,
@@ -101,3 +225,52 @@ svg {
101225
margin: 1.3rem auto;
102226
max-width: 100%;
103227
}
228+
229+
/* Horizontal rule */
230+
hr {
231+
border: none;
232+
border-top: 1px solid var(--mdp-border);
233+
margin: 2rem auto;
234+
}
235+
236+
/* Task lists (GitHub-style checkboxes) */
237+
ul.task-list {
238+
list-style: none;
239+
padding-left: 0;
240+
}
241+
242+
li.task-list-item {
243+
display: flex;
244+
align-items: baseline;
245+
gap: 0.5rem;
246+
}
247+
248+
li.task-list-item > input[type="checkbox"] {
249+
margin: 0;
250+
}
251+
252+
/* Footnotes */
253+
section.footnotes {
254+
margin-top: 3rem;
255+
padding-top: 1rem;
256+
border-top: 1px solid var(--mdp-border);
257+
font-size: 0.9rem;
258+
}
259+
260+
section.footnotes ol {
261+
padding-left: 1.2rem;
262+
}
263+
264+
/* Table of contents */
265+
nav#TOC {
266+
max-width: var(--mdp-content-width);
267+
margin: 0 auto 2rem;
268+
padding: 1rem;
269+
background: var(--mdp-surface);
270+
border: 1px solid var(--mdp-border);
271+
border-radius: 8px;
272+
}
273+
274+
nav#TOC > ul {
275+
margin: 0;
276+
}

0 commit comments

Comments
 (0)