Skip to content

Instantly share code, notes, and snippets.

@Cynede
Created October 21, 2015 12:19
Show Gist options
  • Save Cynede/204a6e12f2914451bb55 to your computer and use it in GitHub Desktop.
Save Cynede/204a6e12f2914451bb55 to your computer and use it in GitHub Desktop.

-- | Raw text will not HTML escape its children.
-- Useful for writing templates.
class Raw arg result | result -> arg where
  raw :: arg    -- ^ Either an attribute list or children.
      -> result -- ^ Result: either an element or an attribute.
  raw = rawWith []
  rawWith :: [Attribute]  -- ^ Attribute transformer.
          -> arg          -- ^ Either an attribute list or children.
          -> result       -- ^ Result: either an element or an attribute.

instance (Monad m, a ~ ()) => Raw Text (HtmlT m a) where
  rawWith f = with x f . toHtmlRaw
    where x = \m' -> HtmlT (do ~(f,a) <- runHtmlT m'
                               return (\attr  -> f mempty, a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment