git.iko.soy/typeable/pandoc
on master help sign in
Changed 'encodeEntities' to 'escapeSGMLString'.
6c3d96afiddlosopher
src/Text/Pandoc/Entities.hs+5−5
@@ -31,9 +31,9 @@ and vice versa.
31module Text.Pandoc.Entities (
31module Text.Pandoc.Entities (
32 charToEntity,
32 charToEntity,
33 charToNumericalEntity,
33 charToNumericalEntity,
34− encodeEntities,
35 decodeEntities,
34 decodeEntities,
36 escapeSGMLChar,
35 escapeSGMLChar,
36+ escapeSGMLString,
37 characterEntity
37 characterEntity
38 ) where
38 ) where
39import Data.Char ( chr, ord )
39import Data.Char ( chr, ord )
@@ -100,12 +100,12 @@ needsEscaping :: Char -> Bool
100needsEscaping c = c `elem` "&<>\""
100needsEscaping c = c `elem` "&<>\""
101
101
102-- | Escape string as needed for SGML. Entity references are not preserved.
102-- | Escape string as needed for SGML. Entity references are not preserved.
103−encodeEntities :: String -> String
103+escapeSGMLString :: String -> String
104−encodeEntities "" = ""
104+escapeSGMLString "" = ""
105−encodeEntities str =
105+escapeSGMLString str =
106 case break needsEscaping str of
106 case break needsEscaping str of
107 (okay, "") -> okay
107 (okay, "") -> okay
108− (okay, (c:cs)) -> okay ++ escapeSGMLChar c ++ encodeEntities cs
108+ (okay, (c:cs)) -> okay ++ escapeSGMLChar c ++ escapeSGMLString cs
109
109
110-- | Convert entities in a string to characters.
110-- | Convert entities in a string to characters.
111decodeEntities :: String -> String
111decodeEntities :: String -> String
src/Text/Pandoc/Shared.hs+3−3
@@ -72,7 +72,7 @@ module Text.Pandoc.Shared (
72 ) where
72 ) where
73import Text.Pandoc.Definition
73import Text.Pandoc.Definition
74import Text.ParserCombinators.Parsec as Parsec
74import Text.ParserCombinators.Parsec as Parsec
75−import Text.Pandoc.Entities ( decodeEntities, encodeEntities )
75+import Text.Pandoc.Entities ( decodeEntities, escapeSGMLString )
76import Text.PrettyPrint.HughesPJ as PP ( text, char, (<>),
76import Text.PrettyPrint.HughesPJ as PP ( text, char, (<>),
77 ($$), nest, Doc, isEmpty )
77 ($$), nest, Doc, isEmpty )
78import Data.Char ( toLower, ord )
78import Data.Char ( toLower, ord )
@@ -524,8 +524,8 @@ replaceRefLinksInline keytable other = other
524-- | Return a text object with a string of formatted SGML attributes.
524-- | Return a text object with a string of formatted SGML attributes.
525attributeList :: [(String, String)] -> Doc
525attributeList :: [(String, String)] -> Doc
526attributeList = text . concatMap
526attributeList = text . concatMap
527− (\(a, b) -> " " ++ encodeEntities a ++ "=\"" ++
527+ (\(a, b) -> " " ++ escapeSGMLString a ++ "=\"" ++
528− encodeEntities b ++ "\"")
528+ escapeSGMLString b ++ "\"")
529
529
530-- | Put the supplied contents between start and end tags of tagType,
530-- | Put the supplied contents between start and end tags of tagType,
531-- with specified attributes and (if specified) indentation.
531-- with specified attributes and (if specified) indentation.
src/Text/Pandoc/Writers/Docbook.hs+11−11
@@ -32,7 +32,7 @@ module Text.Pandoc.Writers.Docbook (
32 ) where
32 ) where
33import Text.Pandoc.Definition
33import Text.Pandoc.Definition
34import Text.Pandoc.Shared
34import Text.Pandoc.Shared
35−import Text.Pandoc.Entities ( encodeEntities )
35+import Text.Pandoc.Entities ( escapeSGMLString )
36import Data.Char ( toLower, ord )
36import Data.Char ( toLower, ord )
37import Data.List ( isPrefixOf, partition, drop )
37import Data.List ( isPrefixOf, partition, drop )
38import Text.PrettyPrint.HughesPJ hiding ( Str )
38import Text.PrettyPrint.HughesPJ hiding ( Str )
@@ -64,8 +64,8 @@ authorToDocbook name = inTagsIndented "author" $
64 then -- last name first
64 then -- last name first
65 let (lastname, rest) = break (==',') name
65 let (lastname, rest) = break (==',') name
66 firstname = removeLeadingSpace rest in
66 firstname = removeLeadingSpace rest in
67− inTagsSimple "firstname" (text $ encodeEntities firstname) <>
67+ inTagsSimple "firstname" (text $ escapeSGMLString firstname) <>
68− inTagsSimple "surname" (text $ encodeEntities lastname)
68+ inTagsSimple "surname" (text $ escapeSGMLString lastname)
69 else -- last name last
69 else -- last name last
70 let namewords = words name
70 let namewords = words name
71 lengthname = length namewords
71 lengthname = length namewords
@@ -73,8 +73,8 @@ authorToDocbook name = inTagsIndented "author" $
73 0 -> ("","")
73 0 -> ("","")
74 1 -> ("", name)
74 1 -> ("", name)
75 n -> (joinWithSep " " (take (n-1) namewords), last namewords) in
75 n -> (joinWithSep " " (take (n-1) namewords), last namewords) in
76− inTagsSimple "firstname" (text $ encodeEntities firstname) $$
76+ inTagsSimple "firstname" (text $ escapeSGMLString firstname) $$
77− inTagsSimple "surname" (text $ encodeEntities lastname)
77+ inTagsSimple "surname" (text $ escapeSGMLString lastname)
78
78
79-- | Convert Pandoc document to string in Docbook format.
79-- | Convert Pandoc document to string in Docbook format.
80writeDocbook :: WriterOptions -> Pandoc -> String
80writeDocbook :: WriterOptions -> Pandoc -> String
@@ -86,7 +86,7 @@ writeDocbook opts (Pandoc (Meta title authors date) blocks) =
86 then inTagsIndented "articleinfo" $
86 then inTagsIndented "articleinfo" $
87 (inTagsSimple "title" (wrap opts title)) $$
87 (inTagsSimple "title" (wrap opts title)) $$
88 (vcat (map authorToDocbook authors)) $$
88 (vcat (map authorToDocbook authors)) $$
89− (inTagsSimple "date" (text $ encodeEntities date))
89+ (inTagsSimple "date" (text $ escapeSGMLString date))
90 else empty
90 else empty
91 blocks' = replaceReferenceLinks blocks
91 blocks' = replaceReferenceLinks blocks
92 (noteBlocks, blocks'') = partition isNoteBlock blocks'
92 (noteBlocks, blocks'') = partition isNoteBlock blocks'
@@ -141,7 +141,7 @@ blockToDocbook opts (Para lst) =
141blockToDocbook opts (BlockQuote blocks) =
141blockToDocbook opts (BlockQuote blocks) =
142 inTagsIndented "blockquote" (blocksToDocbook opts blocks)
142 inTagsIndented "blockquote" (blocksToDocbook opts blocks)
143blockToDocbook opts (CodeBlock str) =
143blockToDocbook opts (CodeBlock str) =
144− text "<screen>\n" <> text (encodeEntities str) <> text "\n</screen>"
144+ text "<screen>\n" <> text (escapeSGMLString str) <> text "\n</screen>"
145blockToDocbook opts (BulletList lst) =
145blockToDocbook opts (BulletList lst) =
146 inTagsIndented "itemizedlist" $ listItemsToDocbook opts lst
146 inTagsIndented "itemizedlist" $ listItemsToDocbook opts lst
147blockToDocbook opts (OrderedList lst) =
147blockToDocbook opts (OrderedList lst) =
@@ -198,7 +198,7 @@ inlinesToDocbook opts lst = hcat (map (inlineToDocbook opts) lst)
198
198
199-- | Convert an inline element to Docbook.
199-- | Convert an inline element to Docbook.
200inlineToDocbook :: WriterOptions -> Inline -> Doc
200inlineToDocbook :: WriterOptions -> Inline -> Doc
201−inlineToDocbook opts (Str str) = text $ encodeEntities str
201+inlineToDocbook opts (Str str) = text $ escapeSGMLString str
202inlineToDocbook opts (Emph lst) =
202inlineToDocbook opts (Emph lst) =
203 inTagsSimple "emphasis" (inlinesToDocbook opts lst)
203 inTagsSimple "emphasis" (inlinesToDocbook opts lst)
204inlineToDocbook opts (Strong lst) =
204inlineToDocbook opts (Strong lst) =
@@ -211,7 +211,7 @@ inlineToDocbook opts Ellipses = text "&#8230;"
211inlineToDocbook opts EmDash = text "&#8212;"
211inlineToDocbook opts EmDash = text "&#8212;"
212inlineToDocbook opts EnDash = text "&#8211;"
212inlineToDocbook opts EnDash = text "&#8211;"
213inlineToDocbook opts (Code str) =
213inlineToDocbook opts (Code str) =
214− inTagsSimple "literal" $ text (encodeEntities str)
214+ inTagsSimple "literal" $ text (escapeSGMLString str)
215inlineToDocbook opts (TeX str) = inlineToDocbook opts (Code str)
215inlineToDocbook opts (TeX str) = inlineToDocbook opts (Code str)
216inlineToDocbook opts (HtmlInline str) = empty
216inlineToDocbook opts (HtmlInline str) = empty
217inlineToDocbook opts LineBreak =
217inlineToDocbook opts LineBreak =
@@ -219,7 +219,7 @@ inlineToDocbook opts LineBreak =
219inlineToDocbook opts Space = char ' '
219inlineToDocbook opts Space = char ' '
220inlineToDocbook opts (Link txt (Src src tit)) =
220inlineToDocbook opts (Link txt (Src src tit)) =
221 if isPrefixOf "mailto:" src
221 if isPrefixOf "mailto:" src
222− then inTagsSimple "email" $ text (encodeEntities $ drop 7 src)
222+ then inTagsSimple "email" $ text (escapeSGMLString $ drop 7 src)
223 else inTags False "ulink" [("url", src)] $ inlinesToDocbook opts txt
223 else inTags False "ulink" [("url", src)] $ inlinesToDocbook opts txt
224inlineToDocbook opts (Link text (Ref ref)) = empty -- shouldn't occur
224inlineToDocbook opts (Link text (Ref ref)) = empty -- shouldn't occur
225inlineToDocbook opts (Image alt (Src src tit)) =
225inlineToDocbook opts (Image alt (Src src tit)) =
@@ -227,7 +227,7 @@ inlineToDocbook opts (Image alt (Src src tit)) =
227 then empty
227 then empty
228 else inTagsIndented "objectinfo" $
228 else inTagsIndented "objectinfo" $
229 inTagsIndented "title"
229 inTagsIndented "title"
230− (text $ encodeEntities tit) in
230+ (text $ escapeSGMLString tit) in
231 inTagsIndented "inlinemediaobject" $
231 inTagsIndented "inlinemediaobject" $
232 inTagsIndented "imageobject" $
232 inTagsIndented "imageobject" $
233 titleDoc $$ selfClosingTag "imagedata" [("fileref", src)]
233 titleDoc $$ selfClosingTag "imagedata" [("fileref", src)]
src/Text/Pandoc/Writers/HTML.hs+7−7
@@ -32,7 +32,7 @@ module Text.Pandoc.Writers.HTML (
32 ) where
32 ) where
33import Text.Pandoc.Definition
33import Text.Pandoc.Definition
34import Text.Pandoc.Shared
34import Text.Pandoc.Shared
35−import Text.Pandoc.Entities ( encodeEntities )
35+import Text.Pandoc.Entities ( escapeSGMLString )
36import Text.Regex ( mkRegex, matchRegex )
36import Text.Regex ( mkRegex, matchRegex )
37import Numeric ( showHex )
37import Numeric ( showHex )
38import Data.Char ( ord, toLower )
38import Data.Char ( ord, toLower )
@@ -127,11 +127,11 @@ htmlHeader opts (Meta title authors date) =
127 then empty
127 then empty
128 else selfClosingTag "meta" [("name", "author"),
128 else selfClosingTag "meta" [("name", "author"),
129 ("content",
129 ("content",
130− joinWithSep ", " (map encodeEntities authors))]
130+ joinWithSep ", " (map escapeSGMLString authors))]
131 datetext = if (date == "")
131 datetext = if (date == "")
132 then empty
132 then empty
133 else selfClosingTag "meta" [("name", "date"),
133 else selfClosingTag "meta" [("name", "date"),
134− ("content", encodeEntities date)] in
134+ ("content", escapeSGMLString date)] in
135 text (writerHeader opts) $$ authortext $$ datetext $$ titletext $$
135 text (writerHeader opts) $$ authortext $$ datetext $$ titletext $$
136 text "</head>\n<body>"
136 text "</head>\n<body>"
137
137
@@ -168,7 +168,7 @@ blockToHtml opts (Note ref lst) =
168 (text "&#8617;")
168 (text "&#8617;")
169blockToHtml opts (Key _ _) = empty
169blockToHtml opts (Key _ _) = empty
170blockToHtml opts (CodeBlock str) =
170blockToHtml opts (CodeBlock str) =
171− text "<pre><code>" <> text (encodeEntities str) <> text "\n</code></pre>"
171+ text "<pre><code>" <> text (escapeSGMLString str) <> text "\n</code></pre>"
172blockToHtml opts (RawHtml str) = text str
172blockToHtml opts (RawHtml str) = text str
173blockToHtml opts (BulletList lst) =
173blockToHtml opts (BulletList lst) =
174 let attribs = if (writerIncremental opts)
174 let attribs = if (writerIncremental opts)
@@ -234,7 +234,7 @@ inlineToHtml opts (Emph lst) =
234inlineToHtml opts (Strong lst) =
234inlineToHtml opts (Strong lst) =
235 inTagsSimple "strong" (inlineListToHtml opts lst)
235 inTagsSimple "strong" (inlineListToHtml opts lst)
236inlineToHtml opts (Code str) =
236inlineToHtml opts (Code str) =
237− inTagsSimple "code" $ text (encodeEntities str)
237+ inTagsSimple "code" $ text (escapeSGMLString str)
238inlineToHtml opts (Quoted SingleQuote lst) =
238inlineToHtml opts (Quoted SingleQuote lst) =
239 text "&lsquo;" <> (inlineListToHtml opts lst) <> text "&rsquo;"
239 text "&lsquo;" <> (inlineListToHtml opts lst) <> text "&rsquo;"
240inlineToHtml opts (Quoted DoubleQuote lst) =
240inlineToHtml opts (Quoted DoubleQuote lst) =
@@ -243,8 +243,8 @@ inlineToHtml opts EmDash = text "&mdash;"
243inlineToHtml opts EnDash = text "&ndash;"
243inlineToHtml opts EnDash = text "&ndash;"
244inlineToHtml opts Ellipses = text "&hellip;"
244inlineToHtml opts Ellipses = text "&hellip;"
245inlineToHtml opts Apostrophe = text "&rsquo;"
245inlineToHtml opts Apostrophe = text "&rsquo;"
246−inlineToHtml opts (Str str) = text $ encodeEntities str
246+inlineToHtml opts (Str str) = text $ escapeSGMLString str
247−inlineToHtml opts (TeX str) = text $ encodeEntities str
247+inlineToHtml opts (TeX str) = text $ escapeSGMLString str
248inlineToHtml opts (HtmlInline str) = text str
248inlineToHtml opts (HtmlInline str) = text str
249inlineToHtml opts (LineBreak) = selfClosingTag "br" []
249inlineToHtml opts (LineBreak) = selfClosingTag "br" []
250inlineToHtml opts Space = space
250inlineToHtml opts Space = space