blaze-from-html 0.3.1.0 → 0.3.2.0
raw patch · 3 files changed
+111/−48 lines, 3 files
Files
- Util/BlazeFromHtml.hs +13/−6
- Util/GenerateHtmlCombinators.hs +66/−18
- blaze-from-html.cabal +32/−24
Util/BlazeFromHtml.hs view
@@ -4,7 +4,8 @@ import Control.Monad (forM_, when) import Control.Applicative ((<$>))-import Data.Maybe (listToMaybe, fromMaybe)+import Data.List (isPrefixOf, stripPrefix)+import Data.Maybe (listToMaybe, fromMaybe, fromJust) import Data.Char (toLower, isSpace) import Control.Arrow (first) import System.Environment (getArgs)@@ -159,11 +160,17 @@ ++ show variant where combinator = qualifiedSanitize "H." tag ++ attributes'- attributes' = attrs >>= \(k, v) -> if k `elem` attributes variant- then " ! " ++ qualifiedSanitize "A." k ++ " " ++ show v- else if ignore- then ""- else error $ "Attribute " ++ k ++ " is illegal in " ++ show variant+ attributes' = attrs >>= \(k, v) -> case k `elem` attributes variant of+ True -> " ! " ++ qualifiedSanitize "A." k ++ " " ++ show v+ False+ | "data-" `isPrefixOf` k -> " ! "+ ++ "dataAttribute" ++ " "+ ++ show (fromJust $ stripPrefix "data-" k)+ ++ " " ++ show v+ | ignore -> ""+ | otherwise -> error $ "Attribute "+ ++ k ++ " is illegal in "+ ++ show variant -- Qualifies a tag with the given qualifier if needed, and sanitizes it. qualifiedSanitize qualifier tag' =
Util/GenerateHtmlCombinators.hs view
@@ -21,12 +21,12 @@ -- | Datatype for an HTML variant. -- data HtmlVariant = HtmlVariant- { version :: [String]- , docType :: [String]- , parents :: [String]- , leafs :: [String]- , attributes :: [String]- , openLeafs :: Bool+ { version :: [String]+ , docType :: [String]+ , parents :: [String]+ , leafs :: [String]+ , attributes :: [String]+ , selfClosing :: Bool } deriving (Eq) instance Show HtmlVariant where@@ -60,7 +60,7 @@ createDirectoryIfMissing True basePath let tags = zip parents' (repeat makeParent)- ++ zip leafs' (repeat $ makeLeaf $ openLeafs htmlVariant)+ ++ zip leafs' (repeat (makeLeaf $ selfClosing htmlVariant)) sortedTags = sortBy (comparing fst) tags appliedTags = map (\(x, f) -> f x) sortedTags @@ -218,10 +218,10 @@ -- | Generate a function for an HTML tag that must be a leaf. ---makeLeaf :: Bool -- ^ If we should use open leafs+makeLeaf :: Bool -- ^ Make leaf tags self-closing -> String -- ^ Tag for the combinator -> String -- ^ Combinator code-makeLeaf openLeaf tag = unlines+makeLeaf closing tag = unlines [ DO_NOT_EDIT , "-- | Combinator for the @\\<" ++ tag ++ " />@ element." , "--"@@ -234,12 +234,12 @@ , "-- > <" ++ tag ++ " />" , "--" , function ++ " :: Html -- ^ Resulting HTML."- , function ++ " = Leaf \"" ++ tag ++ "\" \"<" ++ tag ++ "\" " ++ end+ , function ++ " = Leaf \"" ++ tag ++ "\" \"<" ++ tag ++ "\" " ++ "\""+ ++ (if closing then " /" else "") ++ ">\"" , "{-# INLINE " ++ function ++ " #-}" ] where function = sanitize tag- end = if openLeaf then "\">\"" else "\" />\"" -- | Generate a function for an HTML attribute. --@@ -305,7 +305,7 @@ , "tabindex", "title", "type", "usemap", "valign", "value", "valuetype" , "width" ]- , openLeafs = True+ , selfClosing = False } -- | HTML 4.0 Transitional@@ -326,16 +326,16 @@ [ "background", "bgcolor", "clear", "compact", "hspace", "language" , "noshade", "nowrap", "start", "target", "vspace" ]- , openLeafs = True+ , selfClosing = False } --- | HTML 4.0 Frameset+-- | HTML 4.0 FrameSet -- html4FrameSet :: HtmlVariant html4FrameSet = HtmlVariant { version = ["Html4", "FrameSet"] , docType =- [ "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\""+ [ "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 FrameSet//EN\"" , " \"http://www.w3.org/TR/html4/frameset.dtd\">" ] , parents = parents html4Transitional ++ ["frameset"]@@ -343,9 +343,54 @@ , attributes = attributes html4Transitional ++ [ "frameborder", "scrolling" ]- , openLeafs = True+ , selfClosing = False } +-- | XHTML 1.0 Strict+--+xhtml1Strict :: HtmlVariant+xhtml1Strict = HtmlVariant+ { version = ["XHtml1", "Strict"]+ , docType =+ [ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""+ , " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"+ ]+ , parents = parents html4Strict+ , leafs = leafs html4Strict+ , attributes = attributes html4Strict+ , selfClosing = True+ }++-- | XHTML 1.0 Transitional+--+xhtml1Transitional :: HtmlVariant+xhtml1Transitional = HtmlVariant+ { version = ["XHtml1", "Transitional"]+ , docType =+ [ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\""+ , " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"+ ]+ , parents = parents html4Transitional+ , leafs = leafs html4Transitional+ , attributes = attributes html4Transitional+ , selfClosing = True+ }++-- | XHTML 1.0 FrameSet+--+xhtml1FrameSet :: HtmlVariant+xhtml1FrameSet = HtmlVariant+ { version = ["XHtml1", "FrameSet"]+ , docType =+ [ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 FrameSet//EN\""+ , " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">"+ ]+ , parents = parents html4FrameSet+ , leafs = leafs html4FrameSet+ , attributes = attributes html4FrameSet+ , selfClosing = True+ }+ -- | HTML 5.0 -- A good reference can be found here: -- http://www.w3schools.com/html5/html5_reference.asp@@ -383,7 +428,7 @@ , "hreflang", "http-equiv", "icon", "id", "ismap", "item", "itemprop" , "keytype", "label", "lang", "list", "loop", "low", "manifest", "max" , "maxlength", "media", "method", "min", "multiple", "name"- , "novalidate", "onbeforeonload", "onbeforeprint", "oncanplay"+ , "novalidate", "onbeforeonload", "onbeforeprint", "onblur", "oncanplay" , "oncanplaythrough", "onchange", "oncontextmenu", "onclick" , "ondblclick", "ondrag", "ondragend", "ondragenter", "ondragleave" , "ondragover", "ondragstart", "ondrop", "ondurationchange", "onemptied"@@ -404,7 +449,7 @@ , "summary", "tabindex", "target", "title", "type", "usemap", "value" , "width", "wrap", "xmlns" ]- , openLeafs = False+ , selfClosing = False } -- | A map of HTML variants, per version, lowercase.@@ -414,6 +459,9 @@ [ html4Strict , html4Transitional , html4FrameSet+ , xhtml1Strict+ , xhtml1Transitional+ , xhtml1FrameSet , html5 ]
blaze-from-html.cabal view
@@ -1,26 +1,34 @@-Name: blaze-from-html-Version: 0.3.1.0-Synopsis: Tool to convert HTML to BlazeHtml code.-Description: Tool that converts HTML files to Haskell code, ready to be- used with the BlazeHtml library.-Homepage: http://jaspervdj.be/blaze-Bug-Reports: http://github.com/jaspervdj/BlazeHtml/issues-License: BSD3-License-file: LICENSE-Author: Jasper Van der Jeugt, Simon Meier-Maintainer: jaspervdj@gmail.com, simon.meier@inf.ethz.ch-Stability: Experimental-Category: Text-Build-type: Simple-Cabal-version: >= 1.2+Name: blaze-from-html+Version: 0.3.2.0+Synopsis: Tool to convert HTML to BlazeHtml code.+Description: Tool that converts HTML files to Haskell code, ready to be+ used with the BlazeHtml library.+Homepage: http://jaspervdj.be/blaze+Bug-Reports: http://github.com/jaspervdj/BlazeHtml/issues+License: BSD3+License-file: LICENSE+Author: Jasper Van der Jeugt, Simon Meier+Maintainer: jaspervdj@gmail.com, simon.meier@inf.ethz.ch+Stability: Experimental+Category: Text+Build-type: Simple+Cabal-version: >= 1.6 Executable blaze-from-html- Ghc-Options: -Wall- Main-Is: Util/BlazeFromHtml.hs- Other-Modules: Util.GenerateHtmlCombinators,- Util.Sanitize- Build-depends: base >= 4 && < 5,- containers >= 0.3,- filepath >= 1.1,- directory >= 1.0,- tagsoup >= 0.10+ Ghc-Options: -Wall+ Main-Is: Util/BlazeFromHtml.hs++ Other-Modules:+ Util.GenerateHtmlCombinators+ Util.Sanitize++ Build-depends:+ base >= 4 && < 5,+ containers >= 0.3,+ directory >= 1.0,+ filepath >= 1.1,+ tagsoup >= 0.10++Source-repository head+ Type: git+ Location: http://github.com/jaspervdj/blaze-html.git