diff --git a/src/Text/Pandoc/Writers/Org.hs b/src/Text/Pandoc/Writers/Org.hs index fed334f35..3b7845cc9 100644 --- a/src/Text/Pandoc/Writers/Org.hs +++ b/src/Text/Pandoc/Writers/Org.hs @@ -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 $$ @@ -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 diff --git a/test/Tests/Writers/Org.hs b/test/Tests/Writers/Org.hs index bd6c9b7ab..240bb27e8 100644 --- a/test/Tests/Writers/Org.hs +++ b/test/Tests/Writers/Org.hs @@ -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 diff --git a/test/writer.org b/test/writer.org index 604aca21d..3a1fef604 100644 --- a/test/writer.org +++ b/test/writer.org @@ -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 @@ -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: