Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion commonmark/src/Commonmark/Html.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
module Commonmark.Html
( Html
( Html(..)
, ElementType(..)
, Attribute
, htmlInline
, htmlBlock
, htmlText
Expand All @@ -13,6 +15,8 @@ module Commonmark.Html
, renderHtml
, escapeURI
, escapeHtml
, transform
, transformM
)
where

Expand Down Expand Up @@ -463,3 +467,15 @@ escapeURIChar c
'#','!','$','\'','(',')','*','+',',',
';','=']

-- | Walk HTML nodes bottom-up, applying a function.
transform :: (Html a -> Html a) -> Html a -> Html a
transform f (HtmlElement et name attr (Just elt)) =
f $ HtmlElement et name attr (Just (transform f elt))
transform f elt = f elt

-- | Walk HTML nodes bottom-up, applying a function, in a monadic context.
transformM :: Monad m => (Html a -> m (Html a)) -> Html a -> m (Html a)
transformM f (HtmlElement et name attr (Just elt)) = do
elt' <- transformM f elt
f $ HtmlElement et name attr (Just elt')
transformM f elt = f elt