git.iko.soy/typeable/pandoc
on master help sign in
+ Simplified entity handling by removing stringToSGML from Entities.hs.
dc69255fiddlosopher
src/Text/Pandoc/Entities.hs−18
@@ -34,7 +34,6 @@ module Text.Pandoc.Entities (
34 encodeEntities,
34 encodeEntities,
35 decodeEntities,
35 decodeEntities,
36 escapeSGMLChar,
36 escapeSGMLChar,
37− stringToSGML,
38 characterEntity
37 characterEntity
39 ) where
38 ) where
40import Data.Char ( chr, ord )
39import Data.Char ( chr, ord )
@@ -115,23 +114,6 @@ decodeEntities str =
115 Left err -> error $ "\nError: " ++ show err
114 Left err -> error $ "\nError: " ++ show err
116 Right result -> result
115 Right result -> result
117
116
118−-- | Escape string for SGML, preserving entity references.
119−stringToSGML :: String -> String
120−stringToSGML str =
121− let regular = do
122− str <- many1 (satisfy (not . needsEscaping))
123− return str
124− special = do
125− notFollowedBy characterEntity
126− c <- anyChar
127− return $ escapeSGMLChar c
128− entity = do
129− ent <- manyTill anyChar (char ';')
130− return (ent ++ ";") in
131− case parse (many (regular <|> special <|> entity)) str str of
132− Left err -> error $ "\nError: " ++ show err
133− Right result -> concat result
134−
135entityTable :: [(String, Char)]
117entityTable :: [(String, Char)]
136entityTable = [
118entityTable = [
137 ("&quot;", chr 34),
119 ("&quot;", chr 34),
src/Text/Pandoc/Readers/HTML.hs+3−1
@@ -445,7 +445,9 @@ extractAttribute name [] = Nothing
445extractAttribute name ((attrName, contents):rest) =
445extractAttribute name ((attrName, contents):rest) =
446 let name' = map toLower name
446 let name' = map toLower name
447 attrName' = map toLower attrName in
447 attrName' = map toLower attrName in
448+ if (attrName' == name')
449+ then Just (decodeEntities contents)
448− if (attrName' == name') then Just contents else extractAttribute name rest
450+ else extractAttribute name rest
449
451
450link = try (do
452link = try (do
451 (tag, attributes) <- htmlTag "a"
453 (tag, attributes) <- htmlTag "a"
src/Text/Pandoc/Readers/Markdown.hs+4−4
@@ -42,7 +42,7 @@ import Text.Pandoc.Readers.HTML ( rawHtmlBlock,
42 anyHtmlTag, anyHtmlEndTag,
42 anyHtmlTag, anyHtmlEndTag,
43 htmlEndTag, extractTagType,
43 htmlEndTag, extractTagType,
44 htmlBlockElement )
44 htmlBlockElement )
45−import Text.Pandoc.Entities ( characterEntity )
45+import Text.Pandoc.Entities ( characterEntity, decodeEntities )
46import Text.ParserCombinators.Parsec
46import Text.ParserCombinators.Parsec
47
47
48-- | Read markdown from an input string and return a Pandoc document.
48-- | Read markdown from an input string and return a Pandoc document.
@@ -144,14 +144,14 @@ authorsLine = try (do
144 skipSpaces
144 skipSpaces
145 authors <- sepEndBy (many1 (noneOf ",;\n")) (oneOf ",;")
145 authors <- sepEndBy (many1 (noneOf ",;\n")) (oneOf ",;")
146 newline
146 newline
147− return (map removeLeadingTrailingSpace authors))
147+ return (map (decodeEntities . removeLeadingTrailingSpace) authors))
148
148
149dateLine = try (do
149dateLine = try (do
150 char '%'
150 char '%'
151 skipSpaces
151 skipSpaces
152 date <- many (noneOf "\n")
152 date <- many (noneOf "\n")
153 newline
153 newline
154− return (removeTrailingSpace date))
154+ return (decodeEntities $ removeTrailingSpace date))
155
155
156titleBlock = try (do
156titleBlock = try (do
157 failIfStrict
157 failIfStrict
@@ -894,7 +894,7 @@ titleWith startChar endChar = try (do
894 char endChar
894 char endChar
895 skipSpaces
895 skipSpaces
896 notFollowedBy (noneOf ")\n")))
896 notFollowedBy (noneOf ")\n")))
897− return tit)
897+ return $ decodeEntities tit)
898
898
899title = choice [ titleWith '(' ')',
899title = choice [ titleWith '(' ')',
900 titleWith '"' '"',
900 titleWith '"' '"',
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, stringToSGML )
75+import Text.Pandoc.Entities ( decodeEntities, encodeEntities )
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) -> " " ++ stringToSGML a ++ "=\"" ++
527+ (\(a, b) -> " " ++ encodeEntities a ++ "=\"" ++
528− stringToSGML b ++ "\"")
528+ encodeEntities 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+7−7
@@ -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, stringToSGML )
35+import Text.Pandoc.Entities ( encodeEntities )
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 $ stringToSGML firstname) <>
67+ inTagsSimple "firstname" (text $ encodeEntities firstname) <>
68− inTagsSimple "surname" (text $ stringToSGML lastname)
68+ inTagsSimple "surname" (text $ encodeEntities 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 $ stringToSGML firstname) $$
76+ inTagsSimple "firstname" (text $ encodeEntities firstname) $$
77− inTagsSimple "surname" (text $ stringToSGML lastname)
77+ inTagsSimple "surname" (text $ encodeEntities 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 $ stringToSGML date))
89+ (inTagsSimple "date" (text $ encodeEntities 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'
@@ -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 $ stringToSGML tit) in
230+ (text $ encodeEntities 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+8−10
@@ -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, stringToSGML )
35+import Text.Pandoc.Entities ( encodeEntities )
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 stringToSGML authors))]
130+ joinWithSep ", " (map encodeEntities 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", stringToSGML date)] in
134+ ("content", encodeEntities 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
@@ -248,20 +248,18 @@ inlineToHtml opts (TeX str) = text $ encodeEntities 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
251−inlineToHtml opts (Link txt (Src src tit)) =
251+inlineToHtml opts (Link txt (Src src title)) =
252− let title = stringToSGML tit in
253 if (isPrefixOf "mailto:" src)
252 if (isPrefixOf "mailto:" src)
254 then obfuscateLink opts txt src
253 then obfuscateLink opts txt src
255− else inTags False "a" ([("href", encodeEntities src)] ++
254+ else inTags False "a" ([("href", src)] ++
256− if null tit then [] else [("title", title)])
255+ if null title then [] else [("title", title)])
257 (inlineListToHtml opts txt)
256 (inlineListToHtml opts txt)
258inlineToHtml opts (Link txt (Ref ref)) =
257inlineToHtml opts (Link txt (Ref ref)) =
259 char '[' <> (inlineListToHtml opts txt) <> text "][" <>
258 char '[' <> (inlineListToHtml opts txt) <> text "][" <>
260 (inlineListToHtml opts ref) <> char ']'
259 (inlineListToHtml opts ref) <> char ']'
261 -- this is what markdown does, for better or worse
260 -- this is what markdown does, for better or worse
262−inlineToHtml opts (Image alt (Src source tit)) =
261+inlineToHtml opts (Image alt (Src source title)) =
263− let title = stringToSGML tit
264− alternate = render $ inlineListToHtml opts alt in
262+ let alternate = render $ inlineListToHtml opts alt in
265 selfClosingTag "img" $ [("src", source)] ++
263 selfClosingTag "img" $ [("src", source)] ++
266 (if null alternate then [] else [("alt", alternate)]) ++
264 (if null alternate then [] else [("alt", alternate)]) ++
267 [("title", title)] -- note: null title is included, as in Markdown.pl
265 [("title", title)] -- note: null title is included, as in Markdown.pl