Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Org writer: support starting number cookies #7811

Merged
merged 1 commit into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/Text/Pandoc/Writers/Org.hs
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,9 @@ blockToOrg (OrderedList (start, _, delim) items) = do
x -> x
let markers = 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
counters = (case start of 1 -> Nothing; n -> Just n) : repeat Nothing
contents <- zipWithM (\x f -> f x) items $
zipWith orderedListItemToOrg markers counters
-- ensure that sublists have preceding blank line
return $ blankline $$
(if isTightList items then vcat else vsep) contents $$
Expand All @@ -232,12 +231,17 @@ bulletListItemToOrg items = do
-- | Convert ordered list item (a list of blocks) to Org.
orderedListItemToOrg :: PandocMonad m
=> Text -- ^ marker for list item
-> Maybe Int -- ^ maybe number for a counter cookie
-> [Block] -- ^ list item (list of blocks)
-> Org m (Doc Text)
orderedListItemToOrg marker items = do
orderedListItemToOrg marker counter items = do
exts <- gets $ writerExtensions . stOptions
contents <- blockListToOrg (taskListItemToOrg exts items)
return $ hang (T.length marker + 1) (literal marker <> space) contents $$
let cookie = maybe empty
(\n -> space <> literal "[@" <> literal (tshow n) <> literal "]")
counter
return $ hang (T.length marker + 1)
(literal marker <> cookie <> space) contents $$
if endsWithPlain items
then cr
else 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
8 changes: 4 additions & 4 deletions test/writer.org
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,13 @@ Same thing but with paragraphs:
:CUSTOM_ID: fancy-list-markers
:END:

2) begins with 2
2) [@2] begins with 2

3) and now 3

with a continuation

4. sublist with roman numerals, starting with 4
4. [@4] sublist with roman numerals, starting with 4
5. more items

1) a subsublist
Expand All @@ -296,9 +296,9 @@ Nesting:

1. Upper Roman.

6) Decimal start with 6
6) [@6] Decimal start with 6

3) Lower alpha with paren
3) [@3] Lower alpha with paren

Autonumbering:

Expand Down