Debian Codegraph @

importers/ding2tei/src/Language/TEI/ToXML/Aux.hs

raw symbols SCIP
1 {-
2 - Language/TEI/ToXML/Aux.hs - auxiliary functions for XML generation
3 -
4 - Copyright 2020 Einhard Leichtfuß
5 -
6 - This file is part of ding2tei-haskell.
7 -
8 - ding2tei-haskell is free software: you can redistribute it and/or modify
9 - it under the terms of the GNU Affero General Public License as published
10 - by the Free Software Foundation, either version 3 of the License, or
11 - (at your option) any later version.
12 -
13 - ding2tei-haskell is distributed in the hope that it will be useful,
14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 - GNU Affero General Public License for more details.
17 -
18 - You should have received a copy of the GNU Affero General Public License
19 - along with ding2tei-haskell. If not, see <https://www.gnu.org/licenses/>.
20 -}
21
22
23 {-|
24 - Auxiliary XML generation functions.
25 -
26 - The used `xml' library is very simple; this module tries to compensate
27 - for this.
28 -}
29 module Language.TEI.ToXML.Aux
30 ( uattr
31 , xmlLangAttr
32 , xmlIdAttr
33 , text
34 , mergeContent
35 ) where
36
37
38 import Text.XML.Light
39
40
41 -- | Attribute with unqualified name, analogous to `unode'.
42 uattr :: String -> String -> Attr
43 uattr k v = Attr (unqual k) v
44
45 -- | `@xml:lang' attribute
46 xmlLangAttr :: String -> Attr
47 xmlLangAttr lang = Attr (QName "lang" Nothing (Just "xml")) lang
48
49 -- | `@xml:id' attribute
50 xmlIdAttr :: String -> Attr
51 xmlIdAttr val = Attr (QName "id" Nothing (Just "xml")) val
52
53 -- | Text content. Upon pretty printing, special XML characters are escaped.
54 text :: String -> Content
55 text s = Text $ CData CDataText s Nothing
56
57 -- | Combine adjacent text and elements into the correspondonding string,
58 -- wrapped as a single `Content'.
59 -- This is an ugly workaround to the awkward "pretty" formatting of
60 -- `Text.XML.Light', where a list of `Content' (length >= 2) is always
61 -- converted to a corresponding list of idented lines.
62 mergeContent :: [Content] -> Content
63 mergeContent cs = Text $ CData CDataRaw rawString Nothing
64 where
65 rawString = concatMap (ppcContent defaultConfigPP) cs
66
67
68 -- vi: ft=haskell ts=2 sw=2 et