{-# LANGUAGE OverloadedStrings #-} module Slides.Internal where import Diagrams (Diagram) import Diagrams.Backend.SVG (SVG(..)) import qualified Diagrams as Diag import qualified Diagrams.Backend.SVG as SVG import Slides.Common html :: String -> String -> String html tag content = "<" ++ tag ++ ">" ++ content ++ "" htmlClass :: String -> String -> String -> String htmlClass tag cls content = "<" ++ tag ++ " class=\"" ++ cls ++ "\">" ++ content ++ "" htmlCustom :: String -> String -> String -> String htmlCustom tag att content = "<" ++ tag ++ " " ++ att ++ ">" ++ content ++ "" dropAllButSvg :: String -> String dropAllButSvg ('<' : 's' : 'v' : 'g' : rest) = " tag" svgFromDiagram :: Int -> Diagram SVG -> String svgFromDiagram h = dropAllButSvg . show . Diag.renderDia SVG (SVG.SVGOptions (Diag.mkHeight $ fromIntegral h) Nothing "") renderLeafContent :: ContentNode -> String renderLeafContent (Header h s) = html ("h" ++ show h) s renderLeafContent (Text str) = str renderLeafContent (RawSVG width height str) = htmlCustom "svg" (w ++ " " ++ h) str where w = "width=\"" ++ show width ++ "px\"" h = "height=\"" ++ show height ++ "px\"" renderLeafContent Break = "
" renderLeafContent (Diagram h d) = svgFromDiagram h d