diff options
| author | Albert Krewinkel <[email protected]> | 2025-07-22 18:42:31 +0200 |
|---|---|---|
| committer | Albert Krewinkel <[email protected]> | 2025-07-22 19:07:08 +0200 |
| commit | a45878ff1ecb1af4a508833c05f0922f6ef28498 (patch) | |
| tree | 620fbebac53b3fccefe6bd2e797ea25ffcc335f8 | |
| parent | f596612abd69c4aa517cc59df69ef6c4707f14bc (diff) | |
Markdown writer: match indents in definition items
Previously, the first line of a definition details item always used a
colon and three spaces instead of respecting the tab-stop setting, which
could lead to round-tripping issues.
Likewise, the indentation of continuation paragraphs in definition lists
now matches the two-characters leader of the first line for Markua
output.
Fixes: #10890
| -rw-r--r-- | src/Text/Pandoc/Writers/Markdown.hs | 15 | ||||
| -rw-r--r-- | test/command/10890.md | 15 | ||||
| -rw-r--r-- | test/writer.markua | 14 |
3 files changed, 30 insertions, 14 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index 39abed8fa..cd3e4ab91 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -857,17 +857,18 @@ definitionListItemToMarkdown opts (label, defs) = do let tabStop = writerTabStop opts variant <- asks envVariant let leader = case variant of - PlainText -> " " - Markua -> ":" - _ -> ": " - let sps = case writerTabStop opts - 3 of - n | n > 0 -> literal $ T.replicate n " " - _ -> literal " " + PlainText -> " " + _ -> ":" + let leadingChars = case tabStop of + -- Always use two leading characters for Markua + n | n >= 2 && variant /= Markua -> n + _ -> 2 + let sps = literal $ T.replicate (leadingChars - 1) " " let isTight = case defs of ((Plain _ : _): _) -> True _ -> False let contents = (if isTight then vcat else vsep) $ map - (\d -> hang tabStop (leader <> sps) $ vcat d) + (\d -> hang leadingChars (leader <> sps) $ vcat d) defs' return $ blankline <> nowrap labelText $$ (if isTight then empty else blankline) <> contents <> blankline diff --git a/test/command/10890.md b/test/command/10890.md new file mode 100644 index 000000000..508a9a3d2 --- /dev/null +++ b/test/command/10890.md @@ -0,0 +1,15 @@ +``` +% pandoc --tab-stop=2 --from=native --to=markdown +[ DefinitionList + [ ( [ Str "apple" ] + , [ [ Para [ Str "pomaceous" ] , Para [ Str "fruit" ] ] ] + ) + ] +] +^D +apple + +: pomaceous + + fruit +``` diff --git a/test/writer.markua b/test/writer.markua index a7032dc27..c1ca713d9 100644 --- a/test/writer.markua +++ b/test/writer.markua @@ -317,17 +317,17 @@ Multiple blocks with italics: : red fruit - contains seeds, crisp, pleasant to taste + contains seeds, crisp, pleasant to taste *orange* : orange fruit - ``` - { orange code block } - ``` + ``` + { orange code block } + ``` - > orange block quote + > orange block quote Multiple definitions, tight: @@ -365,8 +365,8 @@ orange : orange fruit - 1. sublist - 2. sublist + 1. sublist + 2. sublist {id: html-blocks} # HTML Blocks |
