Fine-tuning on alerts.

Added a test to show that we can convert smoothly between
gfm, rst, and asciidoc alerts.
This commit is contained in:
John MacFarlane
2023-12-05 09:38:47 -08:00
parent 64bc8ab9c2
commit fe351f1fd5
3 changed files with 42 additions and 10 deletions
+3 -1
View File
@@ -354,7 +354,9 @@ blockToAsciiDoc opts (Div (ident,classes,_) bs) = do
case bs of
(Div (_,["title"],_) ts : rest) -> (ts, rest)
_ -> ([], bs)
admonitionTitle <- if null titleBs
admonitionTitle <- if null titleBs ||
-- If title matches class, omit
(T.toLower (T.strip (stringify titleBs))) == l
then return mempty
else ("." <>) <$>
blockListToAsciiDoc opts titleBs
+10 -9
View File
@@ -370,16 +370,17 @@ blockToMarkdown' :: PandocMonad m
-> MD m (Doc Text)
blockToMarkdown' opts (Div attrs@(_,classes,_) bs)
| isEnabled Ext_alerts opts
, "alert" `elem` classes
, (Div ("", ["alert-title"], []) _ : Para ils : bs') <- bs
, (cls:_) <- classes
, cls `elem` ["note", "tip", "warning", "caution", "important"]
, (Div ("", ["title"], []) _ : Para ils : bs') <- bs
= blockToMarkdown' opts $ BlockQuote $
(Para (RawInline (Format "markdown") (case () of
_ | "alert-note" `elem` classes -> "[!NOTE]\n"
_ | "alert-tip" `elem` classes -> "[!TIP]\n"
_ | "alert-warning" `elem` classes -> "[!WARNING]\n"
_ | "alert-caution" `elem` classes -> "[!CAUTION]\n"
_ | "alert-important" `elem` classes -> "[!IMPORTANT]\n"
| otherwise -> "[!NOTE]\n") : ils)) : bs'
(Para (RawInline (Format "markdown") (case cls of
"note" -> "[!NOTE]\n"
"tip" -> "[!TIP]\n"
"warning" -> "[!WARNING]\n"
"caution" -> "[!CAUTION]\n"
"important" -> "[!IMPORTANT]\n"
_ -> "[!NOTE]\n") : ils)) : bs'
| otherwise = do
contents <- blockListToMarkdown opts bs
variant <- asks envVariant
+29
View File
@@ -0,0 +1,29 @@
```
% pandoc -f rst -t gfm
.. note::
This is my note.
^D
> [!NOTE]
> This is my note.
```
```
% pandoc -f gfm -t rst
> [!WARNING]
> Be careful!
^D
.. warning::
Be careful!
```
```
% pandoc -f gfm -t asciidoc
> [!TIP]
> A tip.
^D
[TIP]
====
A tip.
====
```