Skip to content

Commit

Permalink
blaze-html 0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Apr 23, 2012
1 parent 82b6965 commit e4ca183
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
29 changes: 24 additions & 5 deletions xml2html/Text/XML/Xml2Html.hs
@@ -1,11 +1,22 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE CPP #-}
module Text.XML.Xml2Html () where

#if MIN_VERSION_blaze_html(0, 5, 0)
import qualified Text.XML as X
import qualified Text.Blaze as B
import qualified Text.Blaze.Html as B
import qualified Text.Blaze.Html5 as B5
import qualified Text.Blaze.Internal as BI
#define ToHtml ToMarkup
#define toHtml toMarkup
#else
import qualified Text.XML as X
import qualified Text.Blaze as B
import qualified Text.Blaze.Html5 as B5
import qualified Text.Blaze.Internal as BI
#endif
import qualified Data.Text as T
import Data.String (fromString)
import Data.Monoid (mempty, mappend)
Expand All @@ -14,6 +25,14 @@ import qualified Data.Set as Set
import qualified Data.Map as Map
import Control.Arrow (first)

preEscapedText :: T.Text -> B.Html
preEscapedText =
#if MIN_VERSION_blaze_html(0, 5, 0)
B.preEscapedToMarkup
#else
B.preEscapedText
#endif

instance B.ToHtml X.Document where
toHtml (X.Document _ root _) = B5.docType >> B.toHtml root

Expand All @@ -22,11 +41,11 @@ instance B.ToHtml X.Element where
"{http://www.snoyman.com/xml2html}ie-cond"
[("cond", cond)]
children) =
B.preEscapedText "<!--[if "
`mappend` B.preEscapedText cond
`mappend` B.preEscapedText "]>"
preEscapedText "<!--[if "
`mappend` preEscapedText cond
`mappend` preEscapedText "]>"
`mappend` mapM_ B.toHtml children
`mappend` B.preEscapedText "<![endif]-->"
`mappend` preEscapedText "<![endif]-->"

toHtml (X.Element name' attrs children) =
if isVoid
Expand All @@ -36,7 +55,7 @@ instance B.ToHtml X.Element where
childrenHtml :: B.Html
childrenHtml =
case (name `elem` ["style", "script"], children) of
(True, [X.NodeContent t]) -> B.preEscapedText t
(True, [X.NodeContent t]) -> preEscapedText t
_ -> mapM_ B.toHtml children

isVoid = X.nameLocalName name' `Set.member` voidElems
Expand Down
16 changes: 14 additions & 2 deletions xml2html/xml2html.cabal
@@ -1,5 +1,5 @@
name: xml2html
version: 0.1.2
version: 0.1.2.1
license: BSD3
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>
Expand All @@ -12,12 +12,24 @@ build-type: Simple
homepage: http://github.com/snoyberg/xml
Description: blaze-html instances for xml-conduit types

flag blaze_html_0_5
description: use blaze-html 0.5 and blaze-markup 0.5
default: False

library
build-depends: base >= 4 && < 5
, text >= 0.5 && < 1
, xml-conduit >= 0.5 && < 0.8
, containers >= 0.2 && < 0.5
, blaze-html >= 0.4 && < 0.5

if flag(blaze_html_0_5)
build-depends:
blaze-html >= 0.5 && < 0.6
, blaze-markup >= 0.5.1 && < 0.6
else
build-depends:
blaze-html >= 0.4 && < 0.5

exposed-modules: Text.XML.Xml2Html
ghc-options: -Wall

Expand Down

0 comments on commit e4ca183

Please sign in to comment.