]> Git — Sourcephile - doclang.git/blob - Text/Blaze/DTC.hs
Add Majority Judgment support.
[doclang.git] / Text / Blaze / DTC.hs
1 {-# LANGUAGE OverloadedLists #-}
2 {-# LANGUAGE OverloadedStrings #-}
3 {-# OPTIONS_GHC -fno-warn-orphans #-}
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 import Hdoc.DTC.Document
15
16 -- * Type 'DTC'
17 type DTC = Text.Blaze.XML.XML
18
19 xmlModel :: Text -> DTC
20 xmlModel rnc =
21 Leaf "xml-model" "<?xml-model" "?>\n" ()
22 ! attribute "type" " type=\"" "application/relax-ng-compact-syntax"
23 ! attribute "href" " href=\"" (attrify rnc)
24
25 xmlStylesheet :: Text -> DTC
26 xmlStylesheet xsl =
27 Leaf "xml-stylesheet" "<?xml-stylesheet" "?>\n" ()
28 ! attribute "type" " type=\"" "text/xsl"
29 ! attribute "href" " href=\"" (attrify xsl)
30
31 html5Stylesheet :: Text -> DTC
32 html5Stylesheet xsl =
33 Leaf "html5-stylesheet" "<?html5-stylesheet" "?>\n" ()
34 ! attribute "type" " type=\"" "text/xsl"
35 ! attribute "href" " href=\"" (attrify xsl)
36
37 atomStylesheet :: Text -> DTC
38 atomStylesheet xsl =
39 Leaf "atom-stylesheet" "<?atom-stylesheet" "?>\n" ()
40 ! attribute "type" " type=\"" "text/xsl"
41 ! attribute "href" " href=\"" (attrify xsl)
42
43 about :: DTC -> DTC
44 about = Parent "about" "<about" "</about>"
45 alias :: DTC
46 alias = Leaf "alias" "<alias" "/>" ()
47 artwork :: DTC -> DTC
48 artwork = Parent "artwork" "<artwork" "</artwork>"
49 aside :: DTC -> DTC
50 aside = Parent "aside" "<aside" "</aside>"
51 author :: DTC -> DTC
52 author = Parent "author" "<author" "</author>"
53 b :: DTC -> DTC
54 b = Parent "b" "<b" "</b>"
55 br :: DTC
56 br = Leaf "br" "<br" " />" ()
57 break :: DTC
58 break = Leaf "break" "<break" " />" ()
59 call :: DTC -> DTC
60 call = Parent "call" "<call" "</call>"
61 code :: DTC -> DTC
62 code = Parent "code" "<code" "</code>"
63 comment :: Text -> DTC
64 comment t = Comment (Text t) ()
65 date :: DTC
66 date = Leaf "date" "<date" "/>" ()
67 define :: DTC -> DTC
68 define = Parent "define" "<define" "</define>"
69 del :: DTC -> DTC
70 del = Parent "del" "<del" "</del>"
71 document :: DTC -> DTC
72 document = Parent "document" "<document" "</document>"
73 editor :: DTC -> DTC
74 editor = Parent "editor" "<editor" "</editor>"
75 email :: DTC -> DTC
76 email = Parent "email" "<email" "</email>"
77 entity :: DTC
78 entity = Leaf "entity" "<entity" "/>" ()
79 eref :: DTC -> DTC
80 eref (Empty a) = Leaf "eref" "<eref" "/>" a
81 eref x = Parent "eref" "<eref" "</eref>" x
82 figure :: DTC -> DTC
83 figure = Parent "figure" "<figure" "</figure>"
84 grades :: DTC -> DTC
85 grades = Parent "grades" "<grades" "</grades>"
86 i :: DTC -> DTC
87 i = Parent "i" "<i" "</i>"
88 include :: Bool -> DTC
89 include inc = Leaf "include" "<include" "/>" () !? (not inc, attribute "include" " include=\"" "no")
90 index :: DTC -> DTC
91 index = Parent "index" "<index" "</index>"
92 iref :: DTC -> DTC
93 iref (Empty a) = Leaf "iref" "<iref" "/>" a
94 iref x = Parent "iref" "<iref" "</iref>" x
95 judges :: DTC -> DTC
96 judges = Parent "judges" "<judges" "</judges>"
97 judgment :: DTC -> DTC
98 judgment = Parent "judgment" "<judgment" "</judgment>"
99 li :: DTC -> DTC
100 li = Parent "li" "<li" "</li>"
101 link :: DTC -> DTC
102 link = Parent "link" "<link" "</link>"
103 macro :: DTC -> DTC
104 macro = Parent "macro" "<macro" "</macro>"
105 note :: DTC -> DTC
106 note = Parent "note" "<note" "</note>"
107 ol :: DTC -> DTC
108 ol = Parent "ol" "<ol" "</ol>"
109 organization :: DTC -> DTC
110 organization = Parent "organization" "<organization" "</organization>"
111 p :: DTC -> DTC
112 p = Parent "p" "<p" "</p>"
113 para :: DTC -> DTC
114 para = Parent "para" "<para" "</para>"
115 q :: DTC -> DTC
116 q = Parent "q" "<q" "</q>"
117 quote :: DTC -> DTC
118 quote = Parent "quote" "<quote" "</quote>"
119 ref :: DTC -> DTC
120 ref (Empty a) = Leaf "ref" "<ref" "/>" a
121 ref x = Parent "ref" "<ref" "</ref>" x
122 reference :: DTC -> DTC
123 reference = Parent "reference" "<reference" "</reference>"
124 references :: DTC -> DTC
125 references = Parent "references" "<references" "</references>"
126 rref :: DTC -> DTC
127 rref (Empty a) = Leaf "rref" "<rref" "/>" a
128 rref x = Parent "rref" "<rref" "</rref>" x
129 sc :: DTC -> DTC
130 sc = Parent "sc" "<sc" "</sc>"
131 section :: DTC -> DTC
132 section = Parent "section" "<section" "</section>"
133 span :: DTC -> DTC
134 span = Parent "span" "<span" "</span>"
135 sub :: DTC -> DTC
136 sub = Parent "sub" "<sub" "</sub>"
137 sup :: DTC -> DTC
138 sup = Parent "sup" "<sup" "</sup>"
139 tag :: DTC -> DTC
140 tag = Parent "tag" "<tag" "</tag>"
141 title :: DTC -> DTC
142 title = Parent "title" "<title" "</title>"
143 toc :: DTC
144 toc = Leaf "toc" "<toc" "/>" ()
145 tof :: DTC -> DTC
146 tof = Parent "tof" "<tof" "</tof>"
147 u :: DTC -> DTC
148 u = Parent "u" "<u" "</u>"
149 ul :: DTC -> DTC
150 ul = Parent "ul" "<ul" "</ul>"
151 version :: DTC -> DTC
152 version = Parent "version" "<version" "</version>"
153
154 isInlinedElement :: Text -> Bool
155 isInlinedElement = \case
156 "a" -> True
157 "b" -> True
158 "br" -> True
159 "code" -> True
160 "em" -> True
161 "i" -> True
162 "note" -> True
163 "q" -> True
164 "u" -> True
165 "sup" -> True
166 "sub" -> True
167 _ -> False
168
169 instance Attrify Name where
170 attrify (Name a) = attrify a
171 instance MayAttr Name where
172 mayAttr a (Name t) = mayAttr a t