@@ -32,6 +32,7 @@ Conversion of 'Pandoc' documents to OpenDocument XML.
32module Text.Pandoc.Writers.OpenDocument ( writeOpenDocument ) where
32module Text.Pandoc.Writers.OpenDocument ( writeOpenDocument ) where
33import Text.Pandoc.Definition
33import Text.Pandoc.Definition
34import Text.Pandoc.Shared
34import Text.Pandoc.Shared
35+import Text.Pandoc.XML
35import Text.Pandoc.Readers.TeXMath
36import Text.Pandoc.Readers.TeXMath
36import Text.PrettyPrint.HughesPJ hiding ( Str )
37import Text.PrettyPrint.HughesPJ hiding ( Str )
@@ -39,62 +40,6 @@ import Control.Applicative ((<$>))
39import Control.Monad.State
40import Control.Monad.State
40import Data.Char (chr)
41import Data.Char (chr)
46−-- | Escape one character as needed for XML.
47−escapeCharForXML :: Char -> String
48−escapeCharForXML x = case x of
56−-- | True if the character needs to be escaped.
57−needsEscaping :: Char -> Bool
58−needsEscaping c = c `elem` "&<>\"\160"
60−-- | Escape string as needed for XML. Entity references are not preserved.
61−escapeStringForXML :: String -> String
62−escapeStringForXML "" = ""
63−escapeStringForXML str =
64− case break needsEscaping str of
66− (okay, (c:cs)) -> okay ++ escapeCharForXML c ++ escapeStringForXML cs
68−-- | Return a text object with a string of formatted XML attributes.
69−attributeList :: [(String, String)] -> Doc
70−attributeList = text . concatMap
71− (\(a, b) -> " " ++ escapeStringForXML a ++ "=\"" ++
72− escapeStringForXML b ++ "\"")
74−-- | Put the supplied contents between start and end tags of tagType,
75−-- with specified attributes and (if specified) indentation.
76−inTags:: Bool -> String -> [(String, String)] -> Doc -> Doc
77−inTags isIndented tagType attribs contents =
78− let openTag = char '<' <> text tagType <> attributeList attribs <>
80− closeTag = text "</" <> text tagType <> char '>'
82− then openTag $$ nest 2 contents $$ closeTag
83− else openTag <> contents <> closeTag
85−-- | Return a self-closing tag of tagType with specified attributes
86−selfClosingTag :: String -> [(String, String)] -> Doc
87−selfClosingTag tagType attribs =
88− char '<' <> text tagType <> attributeList attribs <> text " />"
90−-- | Put the supplied contents between start and end tags of tagType.
91−inTagsSimple :: String -> Doc -> Doc
92−inTagsSimple tagType = inTags False tagType []
94−-- | Put the supplied contents in indented block btw start and end tags.
95−inTagsIndented :: String -> Doc -> Doc
96−inTagsIndented tagType = inTags True tagType []
98-- | Auxiliary function to convert Plain block to Para.
43-- | Auxiliary function to convert Plain block to Para.
99plainToPara :: Block -> Block
44plainToPara :: Block -> Block
100plainToPara (Plain x) = Para x
45plainToPara (Plain x) = Para x