aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg <[email protected]>2025-02-09 14:52:50 -0500
committerJohn MacFarlane <[email protected]>2025-05-28 13:38:16 -0700
commitc27ceac5cf801f64dd24b07bba919d1bb281eb81 (patch)
tree0a02506dd060a0544d092bc8aea0bcb022bdfc3b
parent78efe58641b434e301818c96314831da1cf75b2c (diff)
Adding support for sidebars to Asciidoc writer
-rw-r--r--src/Text/Pandoc/Writers/AsciiDoc.hs21
-rw-r--r--test/Tests/Writers/AsciiDoc.hs13
2 files changed, 26 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Writers/AsciiDoc.hs b/src/Text/Pandoc/Writers/AsciiDoc.hs
index c436c5f16..17bbbc000 100644
--- a/src/Text/Pandoc/Writers/AsciiDoc.hs
+++ b/src/Text/Pandoc/Writers/AsciiDoc.hs
@@ -375,29 +375,34 @@ blockToAsciiDoc opts (DefinitionList items) = do
contents <- mapM (definitionListItemToAsciiDoc opts) items
modify $ \st -> st{ inList = inlist }
return $ mconcat contents <> blankline
+
+-- convert admonition and sidebar divs to asicidoc
blockToAsciiDoc opts (Div (ident,classes,_) bs) = do
let identifier = if T.null ident then empty else "[[" <> literal ident <> "]]"
- let admonitions = ["attention","caution","danger","error","hint",
+ let admonition_classes = ["attention","caution","danger","error","hint",
"important","note","tip","warning"]
+ let sidebar_class = "sidebar"
+
contents <-
case classes of
- (l:_) | l `elem` admonitions -> do
+ (l:_) | l `elem` admonition_classes || T.toLower l == sidebar_class -> do
let (titleBs, bodyBs) =
case bs of
(Div (_,["title"],_) ts : rest) -> (ts, rest)
_ -> ([], bs)
- admonitionTitle <- if null titleBs ||
+ let fence = if l == "sidebar" then "****" else "===="
+ elemTitle <- if null titleBs ||
-- If title matches class, omit
(T.toLower (T.strip (stringify titleBs))) == l
then return mempty
else ("." <>) <$>
blockListToAsciiDoc opts titleBs
- admonitionBody <- blockListToAsciiDoc opts bodyBs
+ elemBody <- blockListToAsciiDoc opts bodyBs
return $ "[" <> literal (T.toUpper l) <> "]" $$
- chomp admonitionTitle $$
- "====" $$
- chomp admonitionBody $$
- "===="
+ chomp elemTitle $$
+ fence $$
+ chomp elemBody $$
+ fence
_ -> blockListToAsciiDoc opts bs
return $ identifier $$ contents $$ blankline
diff --git a/test/Tests/Writers/AsciiDoc.hs b/test/Tests/Writers/AsciiDoc.hs
index 4417f6b5c..0fb2aa861 100644
--- a/test/Tests/Writers/AsciiDoc.hs
+++ b/test/Tests/Writers/AsciiDoc.hs
@@ -62,6 +62,19 @@ tests = [ testGroup "emphasis"
, "foo"
, "----"
]
+ , testAsciidoc "sidebar block" $
+ divWith ("sidebar_id", ["sidebar"], [])
+ (divWith ("", ["title"], [])
+ (plain "Sidebar Title")
+ <> para "Sidebar paragraph"
+ ) =?> unlines
+ [ "[[sidebar_id]]"
+ , "[SIDEBAR]"
+ , ".Sidebar Title"
+ , "****"
+ , "Sidebar paragraph"
+ , "****"
+ ]
]
, testGroup "tables"
[ testAsciidoc "empty cells" $