Skip to content
Closed
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 3000.3

- The internal representation has changed from `String` and `[String]` to a
`Data.ByteString.Builder` and difference lists. [#18](https://github.com/haskell/xhtml/pull/18)

## 3000.2.2.1

- Special release which supports *only* `base >= 4.11`
Expand Down
33 changes: 18 additions & 15 deletions Text/XHtml/Debug.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{-# OPTIONS_HADDOCK hide #-}

{-# language OverloadedStrings #-}

-- | This module contains functions for displaying
-- HTML as a pretty tree.
module Text.XHtml.Debug ( HtmlTree(..), treeHtml, treeColors, debugHtml ) where
Expand Down Expand Up @@ -36,13 +38,13 @@ treeHtml colors h = table ! [

treeHtml' :: [String] -> HtmlTree -> HtmlTable
treeHtml' _ (HtmlLeaf leaf) = cell
(td ! [width "100%"]
<< bold
(td ! [width "100%"]
<< bold
<< leaf)
treeHtml' (c:cs@(c2:_)) (HtmlNode hopen ts hclose) =
if null ts && isNoHtml hclose
then
cell hd
cell hd
else if null ts
then
hd </> bar `beside` (td ! [bgcolor' c2] << spaceHtml)
Expand All @@ -67,42 +69,43 @@ treeColors :: [String]
treeColors = ["#88ccff","#ffffaa","#ffaaff","#ccffff"] ++ treeColors


--
--
-- * Html Debugging Combinators
--

-- | This uses the above tree rendering function, and displays the
-- Html as a tree structure, allowing debugging of what is
-- actually getting produced.
debugHtml :: (HTML a) => a -> Html
debugHtml obj = table ! [border 0] <<
debugHtml obj = table ! [border 0] <<
( th ! [bgcolor' "#008888"]
<< underline'
<< "Debugging Output"
<< ("Debugging Output" :: String)
</> td << (toHtml (debug' (toHtml obj)))
)
where

debug' :: Html -> [HtmlTree]
debug' (Html markups) = map debug markups
debug' (Html markups) = map debug (markups [])

debug :: HtmlElement -> HtmlTree
debug (HtmlString str) = HtmlLeaf (spaceHtml +++
linesToHtml (lines str))
linesToHtml (lines (builderToString str)))
debug (HtmlTag {
markupTag = tag',
markupContent = content',
markupAttrs = attrs
markupAttrs = mkAttrs
}) =
case content' of
Html [] -> HtmlNode hd [] noHtml
Html xs -> HtmlNode hd (map debug xs) tl
if isNoHtml content'
then HtmlNode hd [] noHtml
else HtmlNode hd (map debug (getHtmlElements content')) tl
where
attrs = mkAttrs []
args = if null attrs
then ""
else " " ++ unwords (map show attrs)
hd = xsmallFont << ("<" ++ tag' ++ args ++ ">")
tl = xsmallFont << ("</" ++ tag' ++ ">")
else " " <> (unwords (map show attrs))
hd = xsmallFont << ("<" <> builderToString tag' <> args <> ">")
tl = xsmallFont << ("</" <> builderToString tag' <> ">")

bgcolor' :: String -> HtmlAttr
bgcolor' c = thestyle ("background-color:" ++ c)
Expand Down
13 changes: 7 additions & 6 deletions Text/XHtml/Extras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import Text.XHtml.Strict.Attributes
-- | Convert a 'String' to 'Html', converting
-- characters that need to be escaped to HTML entities.
stringToHtml :: String -> Html
stringToHtml = primHtml . stringToHtmlString
stringToHtml = primHtml . builderToString . stringToHtmlString

-- | This converts a string, but keeps spaces as non-line-breakable.
lineToHtml :: String -> Html
lineToHtml = primHtml . concatMap htmlizeChar2 . stringToHtmlString
where
htmlizeChar2 ' ' = "&nbsp;"
htmlizeChar2 c = [c]
lineToHtml =
primHtmlNonEmptyBuilder . stringToHtmlString . foldMap htmlizeChar2
where
htmlizeChar2 ' ' = "&nbsp;"
htmlizeChar2 c = [c]

-- | This converts a string, but keeps spaces as non-line-breakable,
-- and adds line breaks between each of the strings in the input list.
Expand Down Expand Up @@ -76,7 +77,7 @@ hotlink url h = HotLink {
hotLinkAttributes = [] }


--
--
-- * Lists
--

Expand Down
20 changes: 11 additions & 9 deletions Text/XHtml/Frameset.hs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{-# language OverloadedStrings #-}

-- | Produces XHTML 1.0 Frameset.
module Text.XHtml.Frameset (
-- * Data types
Html, HtmlAttr,
-- * Classes
HTML(..), ADDATTRS(..), CHANGEATTRS(..),
-- * Primitives and basic combinators
(<<), concatHtml, (+++),
(<<), concatHtml, (+++),
noHtml, isNoHtml, tag, itag,
htmlAttrPair, emptyAttr, intAttr, strAttr, htmlAttr,
primHtml,
primHtml,
-- * Rendering
showHtml, renderHtml, prettyHtml,
showHtml, renderHtml, prettyHtml,
showHtmlFragment, renderHtmlFragment, prettyHtmlFragment,
module Text.XHtml.Strict.Elements,
module Text.XHtml.Frameset.Elements,
Expand All @@ -28,26 +30,26 @@ import Text.XHtml.Frameset.Attributes

import Text.XHtml.Extras

docType :: String
docType :: Builder
docType =
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"" ++
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"" <>
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">"

-- | Output the HTML without adding newlines or spaces within the markup.
-- This should be the most time and space efficient way to
-- render HTML, though the output is quite unreadable.
showHtml :: HTML html => html -> String
showHtml :: HTML html => html -> Builder
showHtml = showHtmlInternal docType

-- | Outputs indented HTML. Because space matters in
-- HTML, the output is quite messy.
renderHtml :: HTML html => html -> String
renderHtml :: HTML html => html -> Builder
renderHtml = renderHtmlInternal docType

-- | Outputs indented HTML, with indentation inside elements.
-- This can change the meaning of the HTML document, and
-- This can change the meaning of the HTML document, and
-- is mostly useful for debugging the HTML output.
-- The implementation is inefficient, and you are normally
-- better off using 'showHtml' or 'renderHtml'.
prettyHtml :: HTML html => html -> String
prettyHtml = prettyHtmlInternal docType
prettyHtml = prettyHtmlInternal (builderToString docType)
1 change: 1 addition & 0 deletions Text/XHtml/Frameset/Attributes.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# OPTIONS_HADDOCK hide #-}
{-# LANGUAGE OverloadedStrings #-}

module Text.XHtml.Frameset.Attributes where

Expand Down
1 change: 1 addition & 0 deletions Text/XHtml/Frameset/Elements.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# OPTIONS_HADDOCK hide #-}
{-# LANGUAGE OverloadedStrings #-}

module Text.XHtml.Frameset.Elements where

Expand Down
Loading