{-# LANGUAGE GHC2021 #-} {-# LANGUAGE OverloadedStrings #-} -- | Inline data visualizations into the Pandoc AST. -- -- Two fenced-div classes are recognized in Markdown: -- -- __Static figure__ (Matplotlib → SVG, no client-side JS required): -- -- > ::: {.figure script="figures/myplot.py" caption="Caption text"} -- > ::: -- -- Runs the Python script; stdout must be an SVG document with a -- transparent background. Black fills and strokes are replaced with -- @currentColor@ so figures adapt to dark mode automatically. -- See @tools/viz_theme.py@ for the recommended matplotlib setup. -- -- __Interactive figure__ (Altair/Vega-Lite → JSON spec): -- -- > ::: {.visualization script="figures/myplot.py" caption="Caption text"} -- > ::: -- -- Runs the Python script; stdout must be a Vega-Lite JSON spec. The spec -- is embedded verbatim inside a @\" , "" , if T.null caption then "" else "
" <> escHtml caption <> "
" , "" ] errorBlock :: String -> Block errorBlock msg = RawBlock (Format "html") $ T.concat [ "
Visualization error: " , escHtml (T.pack msg) , "
" ] -- --------------------------------------------------------------------------- -- Helpers -- --------------------------------------------------------------------------- attr :: T.Text -> [(T.Text, T.Text)] -> T.Text attr key kvs = fromMaybe "" (lookup key kvs) warn :: String -> String -> IO () warn kind msg = hPutStrLn stderr $ "[Viz] " ++ kind ++ " error: " ++ msg escHtml :: T.Text -> T.Text escHtml = U.escapeHtmlText