mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-23 07:55:45 +00:00
Markdown writer: Fix ordered list bug.
Previously ordered lists starting with a code block did not round trip. Pandoc uses an indented code block, and according to commonmark rules only one space is gobbled after the list marker; however, pandoc added two. This has now been fixed. An incidental change fixes an oddity in markua list indentation. Closes #11762.
This commit is contained in:
@@ -724,13 +724,8 @@ blockToMarkdown' opts (OrderedList (start,sty,delim) items) = do
|
||||
| otherwise = DefaultDelim
|
||||
let attribs = (start', sty', delim')
|
||||
let markers = orderedListMarkers attribs
|
||||
let markers' = case variant of
|
||||
Markua -> markers
|
||||
_ -> map (\m -> if T.length m < 3
|
||||
then m <> T.replicate (3 - T.length m) " "
|
||||
else m) markers
|
||||
contents <- inList $
|
||||
zipWithM (orderedListItemToMarkdown opts) markers' items
|
||||
zipWithM (orderedListItemToMarkdown opts) markers items
|
||||
return $ (if isTightList items then vcat else vsep) contents <> blankline
|
||||
blockToMarkdown' opts (DefinitionList items) = do
|
||||
contents <- inList $ mapM (definitionListItemToMarkdown opts) items
|
||||
@@ -843,15 +838,18 @@ orderedListItemToMarkdown opts marker bs = do
|
||||
let exts = writerExtensions opts
|
||||
contents <- blockListToMarkdown opts $ taskListItemToAscii exts bs
|
||||
variant <- asks envVariant
|
||||
let beginsWithCodeBlock = case bs of
|
||||
CodeBlock{} : _ -> True
|
||||
_ -> False
|
||||
let sps = case writerTabStop opts - T.length marker of
|
||||
n | n > 0 -> literal $ T.replicate n " "
|
||||
_ -> literal " "
|
||||
_ | beginsWithCodeBlock -> 1 -- see #11762
|
||||
_ | variant == Markua -> 1
|
||||
n | n > 0 -> n
|
||||
_ -> 1
|
||||
let ind = if isEnabled Ext_four_space_rule opts
|
||||
then writerTabStop opts
|
||||
else max (writerTabStop opts) (T.length marker + 1)
|
||||
let start = case variant of
|
||||
Markua -> literal marker <> " "
|
||||
_ -> literal marker <> sps
|
||||
else T.length marker + sps
|
||||
let start = literal marker <> literal (T.replicate sps " ")
|
||||
-- remove trailing blank line if item ends with a tight list
|
||||
let contents' = if itemEndsWithTightList bs
|
||||
then chomp contents <> cr
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
```
|
||||
% pandoc -f native -t commonmark | pandoc -f commonmark -t native
|
||||
[ OrderedList
|
||||
( 1 , Decimal , Period )
|
||||
[ [ CodeBlock ( "" , [] , [] ) "hi" ] ]
|
||||
]
|
||||
^D
|
||||
[ OrderedList
|
||||
( 1 , Decimal , Period )
|
||||
[ [ CodeBlock ( "" , [] , [] ) "hi" ] ]
|
||||
]
|
||||
```
|
||||
+16
-16
@@ -192,7 +192,7 @@ Multiple paragraphs:
|
||||
|
||||
1. Item 1, graf one.
|
||||
|
||||
Item 1. graf two. The quick brown fox jumped over the lazy dog’s back.
|
||||
Item 1. graf two. The quick brown fox jumped over the lazy dog’s back.
|
||||
|
||||
2. Item 2.
|
||||
|
||||
@@ -209,9 +209,9 @@ Here’s another:
|
||||
|
||||
1. First
|
||||
2. Second:
|
||||
* Fee
|
||||
* Fie
|
||||
* Foe
|
||||
* Fee
|
||||
* Fie
|
||||
* Foe
|
||||
3. Third
|
||||
|
||||
Same thing but with paragraphs:
|
||||
@@ -220,9 +220,9 @@ Same thing but with paragraphs:
|
||||
|
||||
2. Second:
|
||||
|
||||
* Fee
|
||||
* Fie
|
||||
* Foe
|
||||
* Fee
|
||||
* Fie
|
||||
* Foe
|
||||
|
||||
3. Third
|
||||
|
||||
@@ -244,25 +244,25 @@ Same thing but with paragraphs:
|
||||
|
||||
3) and now 3
|
||||
|
||||
with a continuation
|
||||
with a continuation
|
||||
|
||||
i. sublist with roman numerals starting with i.
|
||||
ii. more items
|
||||
A) a subsublist
|
||||
B) a subsublist
|
||||
i. sublist with roman numerals starting with i.
|
||||
ii. more items
|
||||
A) a subsublist
|
||||
B) a subsublist
|
||||
|
||||
Nesting:
|
||||
|
||||
D. Upper Alpha
|
||||
I. Upper Roman.
|
||||
1) Decimal start with 1
|
||||
a) Lower alpha with paren
|
||||
I. Upper Roman.
|
||||
1) Decimal start with 1
|
||||
a) Lower alpha with paren
|
||||
|
||||
Autonumbering:
|
||||
|
||||
1. Autonumber.
|
||||
2. More.
|
||||
1. Nested.
|
||||
1. Nested.
|
||||
|
||||
Should not be a list item:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user