summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNikolai Korobeinikov <31213770+ricnorr@users.noreply.github.com>2022-01-16 22:05:19 +0300
committerGitHub <noreply@github.com>2022-01-16 11:05:19 -0800
commitb683b8d48aaa68d5e01c000c7641c1337903a586 (patch)
treed5628b94c864d2d2a88714a9d356de8d5fc47ea1 /src
parent1e4829730482665e3e251ac570428dbfc0785ab0 (diff)
Support checklists in asciidoctor writer (#7832)
The checklist syntax (similar to `task_list` in markdown) seems to be an asciidoctor-only addition. Co-authored-by: ricnorr <ricnorr@yandex-tream.ru>
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/AsciiDoc.hs26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Writers/AsciiDoc.hs b/src/Text/Pandoc/Writers/AsciiDoc.hs
index 378d512b6..92442da3c 100644
--- a/src/Text/Pandoc/Writers/AsciiDoc.hs
+++ b/src/Text/Pandoc/Writers/AsciiDoc.hs
@@ -248,13 +248,13 @@ blockToAsciiDoc opts block@(Table _ blkCapt specs thead tbody tfoot) = do
$ zipWith colspec aligns widths')
<> text ","
<> headerspec <> text "]"
-
+
-- construct cells and recurse in case of nested tables
parentTableLevel <- gets tableNestingLevel
let currentNestingLevel = parentTableLevel + 1
-
+
modify $ \st -> st{ tableNestingLevel = currentNestingLevel }
-
+
let separator = text (if parentTableLevel == 0
then "|" -- top level separator
else "!") -- nested separator
@@ -283,7 +283,7 @@ blockToAsciiDoc opts block@(Table _ blkCapt specs thead tbody tfoot) = do
let maxwidth = maximum $ fmap offset (head' :| rows')
let body = if maxwidth > colwidth then vsep rows' else vcat rows'
let border = separator <> text "==="
- return $
+ return $
caption'' $$ tablespec $$ border $$ head'' $$ body $$ border $$ blankline
blockToAsciiDoc opts (BulletList items) = do
inlist <- gets inList
@@ -342,12 +342,26 @@ bulletListItemToAsciiDoc :: PandocMonad m
bulletListItemToAsciiDoc opts blocks = do
lev <- gets bulletListLevel
modify $ \s -> s{ bulletListLevel = lev + 1 }
- contents <- foldM (addBlock opts) empty blocks
+ isAsciidoctor <- gets asciidoctorVariant
+ let blocksWithTasks = if isAsciidoctor
+ then (taskListItemToAsciiDoc blocks)
+ else blocks
+ contents <- foldM (addBlock opts) empty blocksWithTasks
modify $ \s -> s{ bulletListLevel = lev }
let marker = text (replicate (lev + 1) '*')
- return $ marker <> text " " <> listBegin blocks <>
+ return $ marker <> text " " <> listBegin blocksWithTasks <>
contents <> cr
+-- | Convert a list item containing text starting with @U+2610 BALLOT BOX@
+-- or @U+2612 BALLOT BOX WITH X@ to org checkbox syntax (e.g. @[X]@).
+taskListItemToAsciiDoc :: [Block] -> [Block]
+taskListItemToAsciiDoc = handleTaskListItem toOrg listExt
+ where
+ toOrg (Str "☐" : Space : is) = Str "[ ]" : Space : is
+ toOrg (Str "☒" : Space : is) = Str "[X]" : Space : is
+ toOrg is = is
+ listExt = extensionsFromList [Ext_task_lists]
+
addBlock :: PandocMonad m
=> WriterOptions -> Doc Text -> Block -> ADW m (Doc Text)
addBlock opts d b = do