git.iko.soy/typeable/pandoc
on master help sign in
Changed 'encodeEntities' to 'escapeSGMLString'.

git-svn-id: https://pandoc.googlecode.com/svn/trunk@520 788f1e2b-df1e-0410-8736-df70ead52e1b

commit6c3d96a776310a6804c4e9b97df7dbd86450a303 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSun 28 Jan 2007, 16:40 (20 years ago) parentdc69255
4 files changed+26−26
src/Text/Pandoc/Entities.hs+5−5 src/Text/Pandoc/Shared.hs+3−3 src/Text/Pandoc/Writers/Docbook.hs+11−11 src/Text/Pandoc/Writers/HTML.hs+7−7
src/Text/Pandoc/Entities.hs+5−5
@@ -31,9 +31,9 @@ and vice versa.
3131module Text.Pandoc.Entities (
3232 charToEntity,
3333 charToNumericalEntity,
34− encodeEntities,
3534 decodeEntities,
3635 escapeSGMLChar,
36+ escapeSGMLString,
3737 characterEntity
3838 ) where
3939import Data.Char ( chr, ord )
@@ -100,12 +100,12 @@ needsEscaping :: Char -> Bool
100100needsEscaping c = c `elem` "&<>\""
101101
102102-- | Escape string as needed for SGML. Entity references are not preserved.
103−encodeEntities :: String -> String
104−encodeEntities "" = ""
105−encodeEntities str =
103+escapeSGMLString :: String -> String
104+escapeSGMLString "" = ""
105+escapeSGMLString str =
106106 case break needsEscaping str of
107107 (okay, "") -> okay
108− (okay, (c:cs)) -> okay ++ escapeSGMLChar c ++ encodeEntities cs
108+ (okay, (c:cs)) -> okay ++ escapeSGMLChar c ++ escapeSGMLString cs
109109
110110-- | Convert entities in a string to characters.
111111decodeEntities :: String -> String
src/Text/Pandoc/Shared.hs+3−3
@@ -72,7 +72,7 @@ module Text.Pandoc.Shared (
7272 ) where
7373import Text.Pandoc.Definition
7474import Text.ParserCombinators.Parsec as Parsec
75−import Text.Pandoc.Entities ( decodeEntities, encodeEntities )
75+import Text.Pandoc.Entities ( decodeEntities, escapeSGMLString )
7676import Text.PrettyPrint.HughesPJ as PP ( text, char, (<>),
7777 ($$), nest, Doc, isEmpty )
7878import Data.Char ( toLower, ord )
@@ -524,8 +524,8 @@ replaceRefLinksInline keytable other = other
524524-- | Return a text object with a string of formatted SGML attributes.
525525attributeList :: [(String, String)] -> Doc
526526attributeList = text . concatMap
527− (\(a, b) -> " " ++ encodeEntities a ++ "=\"" ++
528− encodeEntities b ++ "\"")
527+ (\(a, b) -> " " ++ escapeSGMLString a ++ "=\"" ++
528+ escapeSGMLString b ++ "\"")
529529
530530-- | Put the supplied contents between start and end tags of tagType,
531531-- with specified attributes and (if specified) indentation.
src/Text/Pandoc/Writers/Docbook.hs+11−11
@@ -32,7 +32,7 @@ module Text.Pandoc.Writers.Docbook (
3232 ) where
3333import Text.Pandoc.Definition
3434import Text.Pandoc.Shared
35−import Text.Pandoc.Entities ( encodeEntities )
35+import Text.Pandoc.Entities ( escapeSGMLString )
3636import Data.Char ( toLower, ord )
3737import Data.List ( isPrefixOf, partition, drop )
3838import Text.PrettyPrint.HughesPJ hiding ( Str )
@@ -64,8 +64,8 @@ authorToDocbook name = inTagsIndented "author" $
6464 then -- last name first
6565 let (lastname, rest) = break (==',') name
6666 firstname = removeLeadingSpace rest in
67− inTagsSimple "firstname" (text $ encodeEntities firstname) <>
68− inTagsSimple "surname" (text $ encodeEntities lastname)
67+ inTagsSimple "firstname" (text $ escapeSGMLString firstname) <>
68+ inTagsSimple "surname" (text $ escapeSGMLString lastname)
6969 else -- last name last
7070 let namewords = words name
7171 lengthname = length namewords
@@ -73,8 +73,8 @@ authorToDocbook name = inTagsIndented "author" $
7373 0 -> ("","")
7474 1 -> ("", name)
7575 n -> (joinWithSep " " (take (n-1) namewords), last namewords) in
76− inTagsSimple "firstname" (text $ encodeEntities firstname) $$
77− inTagsSimple "surname" (text $ encodeEntities lastname)
76+ inTagsSimple "firstname" (text $ escapeSGMLString firstname) $$
77+ inTagsSimple "surname" (text $ escapeSGMLString lastname)
7878
7979-- | Convert Pandoc document to string in Docbook format.
8080writeDocbook :: WriterOptions -> Pandoc -> String
@@ -86,7 +86,7 @@ writeDocbook opts (Pandoc (Meta title authors date) blocks) =
8686 then inTagsIndented "articleinfo" $
8787 (inTagsSimple "title" (wrap opts title)) $$
8888 (vcat (map authorToDocbook authors)) $$
89− (inTagsSimple "date" (text $ encodeEntities date))
89+ (inTagsSimple "date" (text $ escapeSGMLString date))
9090 else empty
9191 blocks' = replaceReferenceLinks blocks
9292 (noteBlocks, blocks'') = partition isNoteBlock blocks'
@@ -141,7 +141,7 @@ blockToDocbook opts (Para lst) =
141141blockToDocbook opts (BlockQuote blocks) =
142142 inTagsIndented "blockquote" (blocksToDocbook opts blocks)
143143blockToDocbook opts (CodeBlock str) =
144− text "<screen>\n" <> text (encodeEntities str) <> text "\n</screen>"
144+ text "<screen>\n" <> text (escapeSGMLString str) <> text "\n</screen>"
145145blockToDocbook opts (BulletList lst) =
146146 inTagsIndented "itemizedlist" $ listItemsToDocbook opts lst
147147blockToDocbook opts (OrderedList lst) =
@@ -198,7 +198,7 @@ inlinesToDocbook opts lst = hcat (map (inlineToDocbook opts) lst)
198198
199199-- | Convert an inline element to Docbook.
200200inlineToDocbook :: WriterOptions -> Inline -> Doc
201−inlineToDocbook opts (Str str) = text $ encodeEntities str
201+inlineToDocbook opts (Str str) = text $ escapeSGMLString str
202202inlineToDocbook opts (Emph lst) =
203203 inTagsSimple "emphasis" (inlinesToDocbook opts lst)
204204inlineToDocbook opts (Strong lst) =
@@ -211,7 +211,7 @@ inlineToDocbook opts Ellipses = text "&#8230;"
211211inlineToDocbook opts EmDash = text "&#8212;"
212212inlineToDocbook opts EnDash = text "&#8211;"
213213inlineToDocbook opts (Code str) =
214− inTagsSimple "literal" $ text (encodeEntities str)
214+ inTagsSimple "literal" $ text (escapeSGMLString str)
215215inlineToDocbook opts (TeX str) = inlineToDocbook opts (Code str)
216216inlineToDocbook opts (HtmlInline str) = empty
217217inlineToDocbook opts LineBreak =
@@ -219,7 +219,7 @@ inlineToDocbook opts LineBreak =
219219inlineToDocbook opts Space = char ' '
220220inlineToDocbook opts (Link txt (Src src tit)) =
221221 if isPrefixOf "mailto:" src
222− then inTagsSimple "email" $ text (encodeEntities $ drop 7 src)
222+ then inTagsSimple "email" $ text (escapeSGMLString $ drop 7 src)
223223 else inTags False "ulink" [("url", src)] $ inlinesToDocbook opts txt
224224inlineToDocbook opts (Link text (Ref ref)) = empty -- shouldn't occur
225225inlineToDocbook opts (Image alt (Src src tit)) =
@@ -227,7 +227,7 @@ inlineToDocbook opts (Image alt (Src src tit)) =
227227 then empty
228228 else inTagsIndented "objectinfo" $
229229 inTagsIndented "title"
230− (text $ encodeEntities tit) in
230+ (text $ escapeSGMLString tit) in
231231 inTagsIndented "inlinemediaobject" $
232232 inTagsIndented "imageobject" $
233233 titleDoc $$ selfClosingTag "imagedata" [("fileref", src)]
src/Text/Pandoc/Writers/HTML.hs+7−7
@@ -32,7 +32,7 @@ module Text.Pandoc.Writers.HTML (
3232 ) where
3333import Text.Pandoc.Definition
3434import Text.Pandoc.Shared
35−import Text.Pandoc.Entities ( encodeEntities )
35+import Text.Pandoc.Entities ( escapeSGMLString )
3636import Text.Regex ( mkRegex, matchRegex )
3737import Numeric ( showHex )
3838import Data.Char ( ord, toLower )
@@ -127,11 +127,11 @@ htmlHeader opts (Meta title authors date) =
127127 then empty
128128 else selfClosingTag "meta" [("name", "author"),
129129 ("content",
130− joinWithSep ", " (map encodeEntities authors))]
130+ joinWithSep ", " (map escapeSGMLString authors))]
131131 datetext = if (date == "")
132132 then empty
133133 else selfClosingTag "meta" [("name", "date"),
134− ("content", encodeEntities date)] in
134+ ("content", escapeSGMLString date)] in
135135 text (writerHeader opts) $$ authortext $$ datetext $$ titletext $$
136136 text "</head>\n<body>"
137137
@@ -168,7 +168,7 @@ blockToHtml opts (Note ref lst) =
168168 (text "&#8617;")
169169blockToHtml opts (Key _ _) = empty
170170blockToHtml 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>"
172172blockToHtml opts (RawHtml str) = text str
173173blockToHtml opts (BulletList lst) =
174174 let attribs = if (writerIncremental opts)
@@ -234,7 +234,7 @@ inlineToHtml opts (Emph lst) =
234234inlineToHtml opts (Strong lst) =
235235 inTagsSimple "strong" (inlineListToHtml opts lst)
236236inlineToHtml opts (Code str) =
237− inTagsSimple "code" $ text (encodeEntities str)
237+ inTagsSimple "code" $ text (escapeSGMLString str)
238238inlineToHtml opts (Quoted SingleQuote lst) =
239239 text "&lsquo;" <> (inlineListToHtml opts lst) <> text "&rsquo;"
240240inlineToHtml opts (Quoted DoubleQuote lst) =
@@ -243,8 +243,8 @@ inlineToHtml opts EmDash = text "&mdash;"
243243inlineToHtml opts EnDash = text "&ndash;"
244244inlineToHtml opts Ellipses = text "&hellip;"
245245inlineToHtml opts Apostrophe = text "&rsquo;"
246−inlineToHtml opts (Str str) = text $ encodeEntities str
247−inlineToHtml opts (TeX str) = text $ encodeEntities str
246+inlineToHtml opts (Str str) = text $ escapeSGMLString str
247+inlineToHtml opts (TeX str) = text $ escapeSGMLString str
248248inlineToHtml opts (HtmlInline str) = text str
249249inlineToHtml opts (LineBreak) = selfClosingTag "br" []
250250inlineToHtml opts Space = space