module HTML where
import XHTML
type TitleStr = String
type StylesheetStr = String
type DTDStr = String
dtdXHTML = "\n\n"
--dtdXHTML = ""
--dtdXHTML = "\n"
type OtherHeads = [XML]
pageString :: DTDStr -> TitleStr -> StylesheetStr -> OtherHeads -> XML -> String
pageString d t s other body =
let title = "title" `around` [txt t]
style = "link" `with` ["href"-->s, "rel"-->"stylesheet", "media"-->"screen",
"type"-->"text/css"]
head = "head" `around` ([title, style]++other)
html = elm "html" ["xmlns"-->"http://www.w3.org/1999/xhtml", "xml:lang"-->"en", "lang"-->"en"] [head, body] --"html" `around` [head, body]
in
d ++ showXHTML 100 html
xhtmlPage title stylesheet otherheads body = cleanup $ pageString dtdXHTML title stylesheet otherheads body
xmlToStr xml = cleanup $ showXHTMLs 100 xml
cleanup = unlines . map (unindentclosingtag 2) . lines
-- was ... . filter nonblank . lines
nonblank [] = False
nonblank ('\r':rest) = nonblank rest
nonblank ('\n':rest) = nonblank rest
nonblank (' ':rest) = nonblank rest
nonblank _ = True
unindentclosingtag n line =
if isonlyclosingtag line
then removeindent n line
else line
isonlyclosingtag (' ':xs) = isonlyclosingtag xs
isonlyclosingtag x = ioct2 x
ioct2 ('<':xs) = ioct3 xs
ioct2 _ = False
ioct3 ('/':xs) = True
ioct3 _ = False
removeindent 0 x = x
removeindent n (' ':xs) = removeindent (n-1) xs
removeindent n x = x