git.iko.soy/typeable/pandoc
on master help sign in
RST reader: Improved admonition support.

* We no longer add an "admonition" class, we just use the class for the type of admonition, "note" for example. * We put the word corresponding to the label in a paragraph inside a div at the beginning of the admonition with class "admonition-title". * This is about as close as we can get to RST's own output. See #223.

commite4d7bed51ceaf2b5b7cb2773fdc6060ca2818fe3 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 7 Feb 2017, 23:07 (10 years ago) parent857d35f
1 file changed+8−6
src/Text/Pandoc/Readers/RST.hs+8−6
src/Text/Pandoc/Readers/RST.hs+8−6
@@ -46,7 +46,7 @@ import Text.Printf ( printf )
4646import Text.Pandoc.Builder (Inlines, Blocks, trimInlines)
4747import qualified Text.Pandoc.Builder as B
4848import Data.Sequence (viewr, ViewR(..))
49−import Data.Char (toLower, isHexDigit, isSpace)
49+import Data.Char (toLower, isHexDigit, isSpace, toUpper)
5050import Data.Monoid ((<>))
5151import Control.Monad.Except (throwError)
5252import Text.Pandoc.Class (PandocMonad, warning, readFileFromDirs,
@@ -633,12 +633,14 @@ directive' = do
633633 "highlights" -> B.blockQuote <$> parseFromString parseBlocks body'
634634 "rubric" -> B.para . B.strong <$> parseInlineFromString top
635635 _ | label `elem` ["attention","caution","danger","error","hint",
636− "important","note","tip","warning"] ->
636+ "important","note","tip","warning","admonition"] ->
637637 do bod <- parseFromString parseBlocks $ top ++ "\n\n" ++ body'
638− return $ B.divWith ("",["admonition", label],[]) bod
639− "admonition" ->
640− do bod <- parseFromString parseBlocks $ top ++ "\n\n" ++ body'
641− return $ B.divWith ("",["admonition"],[]) bod
638+ let lab = case label of
639+ "admonition" -> mempty
640+ (l:ls) -> B.divWith ("",["admonition-title"],[])
641+ (B.para (B.str (toUpper l : ls)))
642+ [] -> mempty
643+ return $ B.divWith ("",[label],[]) (lab <> bod)
642644 "sidebar" ->
643645 do let subtit = maybe "" trim $ lookup "subtitle" fields
644646 tit <- B.para . B.strong <$> parseInlineFromString