module Prettyprinter.Lucid (renderHtml) where import qualified Data.Text as T import Lucid (Html, ToHtml (toHtml), br_, pre_) import Lucid.Base (makeAttribute) import Prettyprinter.Render.Util.SimpleDocTree (SimpleDocTree (..)) renderHtml :: SimpleDocTree (Html () -> Html ()) -> Html () renderHtml :: SimpleDocTree (Html () -> Html ()) -> Html () renderHtml = let go :: SimpleDocTree (Html () -> Html ()) -> Html () go = \case SimpleDocTree (Html () -> Html ()) STEmpty -> () -> Html () forall a. a -> HtmlT Identity a forall (f :: * -> *) a. Applicative f => a -> f a pure () STChar Char c -> Text -> Html () forall a (m :: * -> *). (ToHtml a, Monad m) => a -> HtmlT m () forall (m :: * -> *). Monad m => Text -> HtmlT m () toHtml (Text -> Html ()) -> Text -> Html () forall a b. (a -> b) -> a -> b $ Char -> Text T.singleton Char c STText Int _ Text t -> Text -> Html () forall a (m :: * -> *). (ToHtml a, Monad m) => a -> HtmlT m () forall (m :: * -> *). Monad m => Text -> HtmlT m () toHtml Text t STLine Int i -> [Attribute] -> Html () forall (m :: * -> *). Applicative m => [Attribute] -> HtmlT m () br_ [] Html () -> Html () -> Html () forall a b. HtmlT Identity a -> HtmlT Identity b -> HtmlT Identity b forall (m :: * -> *) a b. Monad m => m a -> m b -> m b >> Text -> Html () forall a (m :: * -> *). (ToHtml a, Monad m) => a -> HtmlT m () forall (m :: * -> *). Monad m => Text -> HtmlT m () toHtml (Int -> Text -> Text T.replicate Int i (Text -> Text) -> Text -> Text forall a b. (a -> b) -> a -> b $ Char -> Text T.singleton Char ' ') STAnn Html () -> Html () ann SimpleDocTree (Html () -> Html ()) content -> Html () -> Html () ann (Html () -> Html ()) -> Html () -> Html () forall a b. (a -> b) -> a -> b $ SimpleDocTree (Html () -> Html ()) -> Html () go SimpleDocTree (Html () -> Html ()) content STConcat [SimpleDocTree (Html () -> Html ())] contents -> (SimpleDocTree (Html () -> Html ()) -> Html ()) -> [SimpleDocTree (Html () -> Html ())] -> Html () forall m a. Monoid m => (a -> m) -> [a] -> m forall (t :: * -> *) m a. (Foldable t, Monoid m) => (a -> m) -> t a -> m foldMap SimpleDocTree (Html () -> Html ()) -> Html () go [SimpleDocTree (Html () -> Html ())] contents in [Attribute] -> Html () -> Html () forall arg result. Term arg result => arg -> result pre_ [Text -> Text -> Attribute makeAttribute Text "style" Text "margin: 0"] (Html () -> Html ()) -> (SimpleDocTree (Html () -> Html ()) -> Html ()) -> SimpleDocTree (Html () -> Html ()) -> Html () forall b c a. (b -> c) -> (a -> b) -> a -> c . SimpleDocTree (Html () -> Html ()) -> Html () go