Skip to content

Commit

Permalink
Org writer: support starting number cookies
Browse files Browse the repository at this point in the history
This complements #7806 by supporting writing Org ordered lists that
start at a specific number.
  • Loading branch information
soficshift committed Jan 7, 2022
1 parent 4be41e3 commit 0ff788f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Text/Pandoc/Writers/Org.hs
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,19 @@ blockToOrg (OrderedList (start, _, delim) items) = do
let delim' = case delim of
TwoParens -> OneParen
x -> x
let markers = take (length items) $ orderedListMarkers
let markers = changeFst (counterCookie start) $
take (length items) $ orderedListMarkers
(start, Decimal, delim')
let maxMarkerLength = maybe 0 maximum . nonEmpty $ map T.length markers
let markers' = map (\m -> let s = maxMarkerLength - T.length m
in m <> T.replicate s " ") markers
contents <- zipWithM orderedListItemToOrg markers' items
contents <- zipWithM orderedListItemToOrg markers items
-- ensure that sublists have preceding blank line
return $ blankline $$
(if isTightList items then vcat else vsep) contents $$
blankline
where
changeFst f (x:xs) = (f x) : xs
changeFst _ [] = []
counterCookie 1 marker = marker
counterCookie n marker = marker <> " [@" <> tshow n <> "]"
blockToOrg (DefinitionList items) = do
contents <- mapM definitionListItemToOrg items
return $ vcat contents $$ blankline
Expand Down
8 changes: 8 additions & 0 deletions test/Tests/Writers/Org.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ tests =
[ "1. [ ] a"
, "2. [X] b"
]
, "ordered task list with starting number"
=: orderedListWith
(9, DefaultStyle, DefaultDelim)
[plain ("" <> space <> "a"), plain "☒ b"]
=?> T.unlines
[ "9. [@9] [ ] a"
, "10. [X] b"
]
, test (orgWithOpts def) "bullet without task_lists" $
bulletList [plain "☐ a", plain "☒ b"]
=?> T.unlines
Expand Down

0 comments on commit 0ff788f

Please sign in to comment.