diff options
| author | Greg <[email protected]> | 2025-02-09 14:52:50 -0500 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2025-05-28 13:38:16 -0700 |
| commit | c27ceac5cf801f64dd24b07bba919d1bb281eb81 (patch) | |
| tree | 0a02506dd060a0544d092bc8aea0bcb022bdfc3b | |
| parent | 78efe58641b434e301818c96314831da1cf75b2c (diff) | |
Adding support for sidebars to Asciidoc writer
| -rw-r--r-- | src/Text/Pandoc/Writers/AsciiDoc.hs | 21 | ||||
| -rw-r--r-- | test/Tests/Writers/AsciiDoc.hs | 13 |
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" $ |
