]> Git — Sourcephile - doclang.git/blob - Text/Blaze/DTC.hs
Factorize XML utilities.
[doclang.git] / Text / Blaze / DTC.hs
1 {-# LANGUAGE OverloadedLists #-}
2 {-# LANGUAGE OverloadedStrings #-}
3 {-# LANGUAGE RecordWildCards #-}
4 module Text.Blaze.DTC where
5
6 import Data.Bool
7 import Data.Text (Text)
8 import Text.Blaze
9 import Text.Blaze.Internal
10
11 import Text.Blaze.Utils
12 import Text.Blaze.XML (XML)
13
14 -- * Type 'DTC'
15 type DTC = XML
16
17 xmlModel :: Text -> DTC
18 xmlModel rnc =
19 Leaf "xml-model" "<?xml-model" "?>\n" ()
20 ! attribute "type" " type=\"" "application/relax-ng-compact-syntax"
21 ! attribute "href" " href=\"" (attrValue rnc)
22
23 xmlStylesheet :: Text -> DTC
24 xmlStylesheet xsl =
25 Leaf "xml-stylesheet" "<?xml-stylesheet" "?>\n" ()
26 ! attribute "type" " type=\"" "text/xsl"
27 ! attribute "href" " href=\"" (attrValue xsl)
28
29 html5Stylesheet :: Text -> DTC
30 html5Stylesheet xsl =
31 Leaf "html5-stylesheet" "<?html5-stylesheet" "?>\n" ()
32 ! attribute "type" " type=\"" "text/xsl"
33 ! attribute "href" " href=\"" (attrValue xsl)
34
35 atomStylesheet :: Text -> DTC
36 atomStylesheet xsl =
37 Leaf "atom-stylesheet" "<?atom-stylesheet" "?>\n" ()
38 ! attribute "type" " type=\"" "text/xsl"
39 ! attribute "href" " href=\"" (attrValue xsl)
40
41 about :: DTC -> DTC
42 about = Parent "about" "<about" "</about>"
43 alias :: DTC
44 alias = Leaf "alias" "<alias" "/>" ()
45 address :: DTC
46 address = Leaf "address" "<address" "/>" ()
47 artwork :: DTC -> DTC
48 artwork = Parent "artwork" "<artwork" "</artwork>"
49 author :: DTC -> DTC
50 author = Parent "author" "<author" "</author>"
51 b :: DTC -> DTC
52 b = Parent "b" "<b" "</b>"
53 br :: DTC
54 br = Leaf "br" "<br" " />" ()
55 call :: DTC -> DTC
56 call = Parent "call" "<call" "</call>"
57 code :: DTC -> DTC
58 code = Parent "code" "<code" "</code>"
59 comment :: Text -> DTC
60 comment t = Comment (Text t) ()
61 date :: DTC
62 date = Leaf "date" "<date" "/>" ()
63 define :: DTC -> DTC
64 define = Parent "define" "<define" "</define>"
65 del :: DTC -> DTC
66 del = Parent "del" "<del" "</del>"
67 document :: DTC -> DTC
68 document = Parent "document" "<document" "</document>"
69 editor :: DTC -> DTC
70 editor = Parent "editor" "<editor" "</editor>"
71 email :: DTC -> DTC
72 email = Parent "email" "<email" "</email>"
73 eref :: DTC -> DTC
74 eref (Empty a) = Leaf "eref" "<eref" "/>" a
75 eref x = Parent "eref" "<eref" "</eref>" x
76 figure :: DTC -> DTC
77 figure = Parent "figure" "<figure" "</figure>"
78 i :: DTC -> DTC
79 i = Parent "i" "<i" "</i>"
80 include :: Bool -> DTC
81 include inc =
82 Leaf "include" "<include" "/>" ()
83 !? (not inc, attribute "include" " include=\"" "no")
84 index :: DTC -> DTC
85 index = Parent "index" "<index" "</index>"
86 iref :: DTC -> DTC
87 iref (Empty a) = Leaf "iref" "<iref" "/>" a
88 iref x = Parent "iref" "<iref" "</iref>" x
89 keyword :: DTC -> DTC
90 keyword = Parent "keyword" "<keyword" "</keyword>"
91 li :: DTC -> DTC
92 li = Parent "li" "<li" "</li>"
93 link :: DTC -> DTC
94 link = Parent "link" "<link" "</link>"
95 macro :: DTC -> DTC
96 macro = Parent "macro" "<macro" "</macro>"
97 note :: DTC -> DTC
98 note = Parent "note" "<note" "</note>"
99 ol :: DTC -> DTC
100 ol = Parent "ol" "<ol" "</ol>"
101 organization :: DTC -> DTC
102 organization = Parent "organization" "<organization" "</organization>"
103 para :: DTC -> DTC
104 para = Parent "para" "<para" "</para>"
105 q :: DTC -> DTC
106 q = Parent "q" "<q" "</q>"
107 quote :: DTC -> DTC
108 quote = Parent "quote" "<quote" "</quote>"
109 ref :: DTC -> DTC
110 ref (Empty a) = Leaf "ref" "<ref" "/>" a
111 ref x = Parent "ref" "<ref" "</ref>" x
112 reference :: DTC -> DTC
113 reference = Parent "reference" "<reference" "</reference>"
114 rl :: DTC -> DTC
115 rl = Parent "rl" "<rl" "</rl>"
116 rref :: DTC -> DTC
117 rref (Empty a) = Leaf "rref" "<rref" "/>" a
118 rref x = Parent "rref" "<rref" "</rref>" x
119 sc :: DTC -> DTC
120 sc = Parent "sc" "<sc" "</sc>"
121 section :: DTC -> DTC
122 section = Parent "section" "<section" "</section>"
123 sub :: DTC -> DTC
124 sub = Parent "sub" "<sub" "</sub>"
125 sup :: DTC -> DTC
126 sup = Parent "sup" "<sup" "</sup>"
127 title :: DTC -> DTC
128 title = Parent "title" "<title" "</title>"
129 toc :: DTC
130 toc = Leaf "toc" "<toc" "/>" ()
131 tof :: DTC
132 tof = Leaf "tof" "<tof" "/>" ()
133 u :: DTC -> DTC
134 u = Parent "u" "<u" "</u>"
135 ul :: DTC -> DTC
136 ul = Parent "ul" "<ul" "</ul>"
137 version :: DTC -> DTC
138 version = Parent "version" "<version" "</version>"
139
140 indentTag :: Text -> IndentTag
141 indentTag t =
142 case t of
143 "about" -> IndentTagChildren
144 "address" -> IndentTagChildren
145 "author" -> IndentTagChildren
146 "document" -> IndentTagChildren
147 "editor" -> IndentTagChildren
148 "figure" -> IndentTagChildren
149 "ol" -> IndentTagChildren
150 "postal" -> IndentTagChildren
151 "reference" -> IndentTagChildren
152 "rl" -> IndentTagChildren
153 "section" -> IndentTagChildren
154 "ul" -> IndentTagChildren
155 "a" -> IndentTagText
156 "b" -> IndentTagText
157 "i" -> IndentTagText
158 "li" -> IndentTagText
159 "para" -> IndentTagText
160 "q" -> IndentTagText
161 "quote" -> IndentTagText
162 "note" -> IndentTagText
163 _ -> IndentTagPreserve