Skip to content

Commit 8ce63ff

Browse files
committed
Mardkown writer: fix spacing issues with definition lists.
- Properly handle the case where the first item is an indented code block. (Closes #11542.) - Use correct indentation when `four_space_rule` extension is disabled.
1 parent f1e0614 commit 8ce63ff

8 files changed

Lines changed: 117 additions & 65 deletions

File tree

‎src/Text/Pandoc/Writers/Markdown.hs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,10 @@ blockToMarkdown' opts (CodeBlock attribs str) = do
578578
tildes <> attrs <> cr <> literal str <> cr <> tildes <> blankline
579579
_ | variant == Markua -> blankline <> attrsToMarkua opts attribs <> cr <> backticks <> cr <>
580580
literal str <> cr <> backticks <> cr <> blankline
581-
| otherwise -> nest (writerTabStop opts) (literal str) <> blankline
581+
| otherwise -> -- don't use nest: see #11542
582+
let addIndent "" = "\n"
583+
addIndent x = (T.replicate (writerTabStop opts) " ") <> x <> "\n"
584+
in literal (mconcat $ map addIndent (T.lines str)) $$ blankline
582585
where
583586
endlineLen c = maybe 3 ((+1) . maximum) $ nonEmpty
584587
[T.length ln
@@ -862,8 +865,10 @@ definitionListItemToMarkdown opts (label, defs) = do
862865
_ -> ":"
863866
let leadingChars = case tabStop of
864867
-- Always use two leading characters for Markua
865-
n | n >= 2 && variant /= Markua -> n
866-
_ -> 2
868+
n | variant == Markua -> 2
869+
| isEnabled Ext_four_space_rule opts
870+
, n >= 2 -> n
871+
| otherwise -> 2
867872
let sps = literal $ T.replicate (leadingChars - 1) " "
868873
let isTight = case defs of
869874
((Plain _ : _): _) -> True

‎test/command/11542.md‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
```
2+
% pandoc -f native -t markdown
3+
[ DefinitionList
4+
[ ( [ Str "Input" ]
5+
, [ [ CodeBlock ( "" , [] , [] ) "Term\n\n : Def" ] ]
6+
)
7+
]
8+
]
9+
^D
10+
Input
11+
12+
: Term
13+
14+
: Def
15+
```
16+
17+
```
18+
% pandoc -f markdown -t native
19+
Input
20+
21+
: Term
22+
23+
: Def
24+
^D
25+
[ DefinitionList
26+
[ ( [ Str "Input" ]
27+
, [ [ CodeBlock ( "" , [] , [] ) "Term\n\n : Def" ] ]
28+
)
29+
]
30+
]
31+
```
32+
33+
```
34+
% pandoc -f native -t markdown+four_space_rule
35+
[ DefinitionList
36+
[ ( [ Str "Input" ]
37+
, [ [ CodeBlock ( "" , [] , [] ) "Term\n\n : Def" ] ]
38+
)
39+
]
40+
]
41+
^D
42+
Input
43+
44+
: Term
45+
46+
: Def
47+
```

‎test/command/5543.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
: description
55
^D
66
1\. item
7-
: description
7+
: description
88
```

‎test/command/6858.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ Module FvwmAnimate \[ModuleAlias\]
2727
2828
\*FvwmAnimate: Color color
2929
30-
: Tells **FvwmAnimate** what color to draw with. The color is
31-
\"XOR\'ed\" (exclusive ORed) onto the background.
30+
: Tells **FvwmAnimate** what color to draw with. The color is
31+
\"XOR\'ed\" (exclusive ORed) onto the background.
3232
3333
\*FvwmAnimate: Pixmap pixmap
3434
35-
: Tells **FvwmAnimate** to use **pixmap** to draw with. This can be
36-
useful if **\*FvwmAnimate: Color** gives poor results.
35+
: Tells **FvwmAnimate** to use **pixmap** to draw with. This can be
36+
useful if **\*FvwmAnimate: Color** gives poor results.
3737
```
3838

3939
```

‎test/command/9201.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This is line two.
1212
1313
**\--help**
1414
15-
: This is line one.
15+
: This is line one.
1616
17-
This is line two.
17+
This is line two.
1818
```

‎test/writer.markdown‎

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -261,93 +261,93 @@ B. Williams
261261
Tight using spaces:
262262

263263
apple
264-
: red fruit
264+
: red fruit
265265

266266
orange
267-
: orange fruit
267+
: orange fruit
268268

269269
banana
270-
: yellow fruit
270+
: yellow fruit
271271

272272
Tight using tabs:
273273

274274
apple
275-
: red fruit
275+
: red fruit
276276

277277
orange
278-
: orange fruit
278+
: orange fruit
279279

280280
banana
281-
: yellow fruit
281+
: yellow fruit
282282

283283
Loose:
284284

285285
apple
286286

287-
: red fruit
287+
: red fruit
288288

289289
orange
290290

291-
: orange fruit
291+
: orange fruit
292292

293293
banana
294294

295-
: yellow fruit
295+
: yellow fruit
296296

297297
Multiple blocks with italics:
298298

299299
*apple*
300300

301-
: red fruit
301+
: red fruit
302302

303-
contains seeds, crisp, pleasant to taste
303+
contains seeds, crisp, pleasant to taste
304304

305305
*orange*
306306

307-
: orange fruit
307+
: orange fruit
308308

309-
{ orange code block }
309+
{ orange code block }
310310

311-
> orange block quote
311+
> orange block quote
312312
313313
Multiple definitions, tight:
314314

315315
apple
316-
: red fruit
317-
: computer
316+
: red fruit
317+
: computer
318318

319319
orange
320-
: orange fruit
321-
: bank
320+
: orange fruit
321+
: bank
322322

323323
Multiple definitions, loose:
324324

325325
apple
326326

327-
: red fruit
327+
: red fruit
328328

329-
: computer
329+
: computer
330330

331331
orange
332332

333-
: orange fruit
333+
: orange fruit
334334

335-
: bank
335+
: bank
336336

337337
Blank line after term, indented marker, alternate markers:
338338

339339
apple
340340

341-
: red fruit
341+
: red fruit
342342

343-
: computer
343+
: computer
344344

345345
orange
346346

347-
: orange fruit
347+
: orange fruit
348348

349-
1. sublist
350-
2. sublist
349+
1. sublist
350+
2. sublist
351351

352352
# HTML Blocks
353353

‎test/writer.opml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<outline text="Fancy list markers" _note="(2) begins with 2&#10;&#10;(3) and now 3&#10;&#10; with a continuation&#10;&#10; iv. sublist with roman numerals, starting with 4&#10; v. more items&#10; (A) a subsublist&#10; (B) a subsublist&#10;&#10;Nesting:&#10;&#10;A. Upper Alpha&#10; I. Upper Roman.&#10; (6) Decimal start with 6&#10; c) Lower alpha with paren&#10;&#10;Autonumbering:&#10;&#10;1. Autonumber.&#10;2. More.&#10; 1. Nested.&#10;&#10;Should not be a list item:&#10;&#10;M.A. 2007&#10;&#10;B. Williams&#10;&#10;--------------------------------------------------------------------------------">
4343
</outline>
4444
</outline>
45-
<outline text="Definition Lists" _note="Tight using spaces:&#10;&#10;apple&#10;: red fruit&#10;&#10;orange&#10;: orange fruit&#10;&#10;banana&#10;: yellow fruit&#10;&#10;Tight using tabs:&#10;&#10;apple&#10;: red fruit&#10;&#10;orange&#10;: orange fruit&#10;&#10;banana&#10;: yellow fruit&#10;&#10;Loose:&#10;&#10;apple&#10;&#10;: red fruit&#10;&#10;orange&#10;&#10;: orange fruit&#10;&#10;banana&#10;&#10;: yellow fruit&#10;&#10;Multiple blocks with italics:&#10;&#10;*apple*&#10;&#10;: red fruit&#10;&#10; contains seeds, crisp, pleasant to taste&#10;&#10;*orange*&#10;&#10;: orange fruit&#10;&#10; { orange code block }&#10;&#10; &gt; orange block quote&#10;&#10;Multiple definitions, tight:&#10;&#10;apple&#10;: red fruit&#10;: computer&#10;&#10;orange&#10;: orange fruit&#10;: bank&#10;&#10;Multiple definitions, loose:&#10;&#10;apple&#10;&#10;: red fruit&#10;&#10;: computer&#10;&#10;orange&#10;&#10;: orange fruit&#10;&#10;: bank&#10;&#10;Blank line after term, indented marker, alternate markers:&#10;&#10;apple&#10;&#10;: red fruit&#10;&#10;: computer&#10;&#10;orange&#10;&#10;: orange fruit&#10;&#10; 1. sublist&#10; 2. sublist">
45+
<outline text="Definition Lists" _note="Tight using spaces:&#10;&#10;apple&#10;: red fruit&#10;&#10;orange&#10;: orange fruit&#10;&#10;banana&#10;: yellow fruit&#10;&#10;Tight using tabs:&#10;&#10;apple&#10;: red fruit&#10;&#10;orange&#10;: orange fruit&#10;&#10;banana&#10;: yellow fruit&#10;&#10;Loose:&#10;&#10;apple&#10;&#10;: red fruit&#10;&#10;orange&#10;&#10;: orange fruit&#10;&#10;banana&#10;&#10;: yellow fruit&#10;&#10;Multiple blocks with italics:&#10;&#10;*apple*&#10;&#10;: red fruit&#10;&#10; contains seeds, crisp, pleasant to taste&#10;&#10;*orange*&#10;&#10;: orange fruit&#10;&#10; { orange code block }&#10;&#10; &gt; orange block quote&#10;&#10;Multiple definitions, tight:&#10;&#10;apple&#10;: red fruit&#10;: computer&#10;&#10;orange&#10;: orange fruit&#10;: bank&#10;&#10;Multiple definitions, loose:&#10;&#10;apple&#10;&#10;: red fruit&#10;&#10;: computer&#10;&#10;orange&#10;&#10;: orange fruit&#10;&#10;: bank&#10;&#10;Blank line after term, indented marker, alternate markers:&#10;&#10;apple&#10;&#10;: red fruit&#10;&#10;: computer&#10;&#10;orange&#10;&#10;: orange fruit&#10;&#10; 1. sublist&#10; 2. sublist">
4646
</outline>
4747
<outline text="HTML Blocks" _note="Simple block on one line:&#10;&#10;::: {}&#10;foo&#10;:::&#10;&#10;And nested without indentation:&#10;&#10;:::::: {}&#10;:::: {}&#10;::: {}&#10;foo&#10;:::&#10;::::&#10;&#10;::: {}&#10;bar&#10;:::&#10;::::::&#10;&#10;Interpreted markdown in a table:&#10;&#10;&lt;table&gt;&#10;&lt;tr&gt;&#10;&lt;td&gt;&#10;This is *emphasized*&#10;&lt;/td&gt;&#10;&lt;td&gt;&#10;And this is **strong**&#10;&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;/table&gt;&#10;&lt;script type=&quot;text/javascript&quot;&gt;document.write('This *should not* be interpreted as markdown');&lt;/script&gt;&#10;&#10;Here's a simple block:&#10;&#10;::: {}&#10;foo&#10;:::&#10;&#10;This should be a code block, though:&#10;&#10; &lt;div&gt;&#10; foo&#10; &lt;/div&gt;&#10;&#10;As should this:&#10;&#10; &lt;div&gt;foo&lt;/div&gt;&#10;&#10;Now, nested:&#10;&#10;::::: {}&#10;:::: {}&#10;::: {}&#10;foo&#10;:::&#10;::::&#10;:::::&#10;&#10;This should just be an HTML comment:&#10;&#10;&lt;!-- Comment --&gt;&#10;&#10;Multiline:&#10;&#10;&lt;!--&#10;Blah&#10;Blah&#10;--&gt;&#10;&lt;!--&#10; This is another comment.&#10;--&gt;&#10;&#10;Code block:&#10;&#10; &lt;!-- Comment --&gt;&#10;&#10;Just plain comment, with trailing spaces on the line:&#10;&#10;&lt;!-- foo --&gt;&#10;&#10;Code:&#10;&#10; &lt;hr /&gt;&#10;&#10;Hr's:&#10;&#10;&lt;hr&gt;&#10;&lt;hr /&gt;&#10;&lt;hr /&gt;&#10;&lt;hr&gt;&#10;&lt;hr /&gt;&#10;&lt;hr /&gt;&#10;&lt;hr class=&quot;foo&quot; id=&quot;bar&quot; /&gt;&#10;&lt;hr class=&quot;foo&quot; id=&quot;bar&quot; /&gt;&#10;&lt;hr class=&quot;foo&quot; id=&quot;bar&quot;&gt;&#10;&#10;--------------------------------------------------------------------------------">
4848
</outline>

‎test/writer.plain‎

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -257,93 +257,93 @@ Definition Lists
257257
Tight using spaces:
258258

259259
apple
260-
red fruit
260+
red fruit
261261

262262
orange
263-
orange fruit
263+
orange fruit
264264

265265
banana
266-
yellow fruit
266+
yellow fruit
267267

268268
Tight using tabs:
269269

270270
apple
271-
red fruit
271+
red fruit
272272

273273
orange
274-
orange fruit
274+
orange fruit
275275

276276
banana
277-
yellow fruit
277+
yellow fruit
278278

279279
Loose:
280280

281281
apple
282282

283-
red fruit
283+
red fruit
284284

285285
orange
286286

287-
orange fruit
287+
orange fruit
288288

289289
banana
290290

291-
yellow fruit
291+
yellow fruit
292292

293293
Multiple blocks with italics:
294294

295295
apple
296296

297-
red fruit
297+
red fruit
298298

299-
contains seeds, crisp, pleasant to taste
299+
contains seeds, crisp, pleasant to taste
300300

301301
orange
302302

303-
orange fruit
303+
orange fruit
304304

305-
{ orange code block }
305+
{ orange code block }
306306

307-
orange block quote
307+
orange block quote
308308

309309
Multiple definitions, tight:
310310

311311
apple
312-
red fruit
313-
computer
312+
red fruit
313+
computer
314314

315315
orange
316-
orange fruit
317-
bank
316+
orange fruit
317+
bank
318318

319319
Multiple definitions, loose:
320320

321321
apple
322322

323-
red fruit
323+
red fruit
324324

325-
computer
325+
computer
326326

327327
orange
328328

329-
orange fruit
329+
orange fruit
330330

331-
bank
331+
bank
332332

333333
Blank line after term, indented marker, alternate markers:
334334

335335
apple
336336

337-
red fruit
337+
red fruit
338338

339-
computer
339+
computer
340340

341341
orange
342342

343-
orange fruit
343+
orange fruit
344344

345-
1. sublist
346-
2. sublist
345+
1. sublist
346+
2. sublist
347347

348348
HTML Blocks
349349

0 commit comments

Comments
 (0)