git.iko.soy/typeable/pandoc
on master help sign in
Don't escape URIs in HTML writer.

This should be done in the readers instead.

commit09ca37bd62ca953fff69b58959e398f9ec31834f authorJohn MacFarlane <jgm@berkeley.edu> dateTue 23 Mar 2010, 14:02 (17 years ago) parent9e65867
1 file changed+12−20
src/Text/Pandoc/Writers/HTML.hs+12−20
src/Text/Pandoc/Writers/HTML.hs+12−20
@@ -67,14 +67,6 @@ renderFragment opts = if writerWrapText opts
6767stringToHtml :: String -> Html
6868stringToHtml = primHtml . escapeStringForXML
6969
70−-- Note: href and src, unmodified, incorrectly escape high
71−-- characters in URIs using entities. So we use these replacements:
72−href' :: String -> HtmlAttr
73−href' = href . stringToURI
74−
75−src' :: String -> HtmlAttr
76−src' = src . stringToURI
77−
7870-- | Convert Pandoc document to Html string.
7971writeHtmlString :: WriterOptions -> Pandoc -> String
8072writeHtmlString opts d =
@@ -120,13 +112,13 @@ pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do
120112 then case writerHTMLMathMethod opts of
121113 LaTeXMathML (Just url) ->
122114 script !
123− [src' url, thetype "text/javascript"] $ noHtml
115+ [src url, thetype "text/javascript"] $ noHtml
124116 MathML (Just url) ->
125117 script !
126− [src' url, thetype "text/javascript"] $ noHtml
118+ [src url, thetype "text/javascript"] $ noHtml
127119 JsMath (Just url) ->
128120 script !
129− [src' url, thetype "text/javascript"] $ noHtml
121+ [src url, thetype "text/javascript"] $ noHtml
130122 _ -> case lookup "mathml-script" (writerVariables opts) of
131123 Just s ->
132124 script ! [thetype "text/javascript"] <<
@@ -196,7 +188,7 @@ elementToListItem opts (Sec _ num id' headerText subsecs) = do
196188 let subList = if null subHeads
197189 then noHtml
198190 else unordList subHeads
199− return $ Just $ (anchor ! [href' ("#" ++ writerIdentifierPrefix opts ++ id')] $ txt) +++ subList
191+ return $ Just $ (anchor ! [href ("#" ++ writerIdentifierPrefix opts ++ id')] $ txt) +++ subList
200192
201193-- | Convert an Element to Html.
202194elementToHtml :: WriterOptions -> Element -> State WriterState Html
@@ -230,7 +222,7 @@ parseMailto _ = Nothing
230222-- | Obfuscate a "mailto:" link.
231223obfuscateLink :: WriterOptions -> String -> String -> Html
232224obfuscateLink opts txt s | writerEmailObfuscation opts == NoObfuscation =
233− anchor ! [href' s] << txt
225+ anchor ! [href s] << txt
234226obfuscateLink opts txt s =
235227 let meth = writerEmailObfuscation opts
236228 s' = map toLower s
@@ -257,7 +249,7 @@ obfuscateLink opts txt s =
257249 linkText ++ "+'<\\/'+'a'+'>');\n// -->\n")) +++
258250 noscript (primHtml $ obfuscateString altText)
259251 _ -> error $ "Unknown obfuscation method: " ++ show meth
260− _ -> anchor ! [href' s] $ stringToHtml txt -- malformed email
252+ _ -> anchor ! [href s] $ stringToHtml txt -- malformed email
261253
262254-- | Obfuscate character as entity.
263255obfuscateChar :: Char -> String
@@ -320,7 +312,7 @@ blockToHtml opts (Header level lst) = do
320312 stringToHtml " " +++ contents
321313 else contents
322314 let contents'' = if writerTableOfContents opts
323− then anchor ! [href' $ "#" ++ writerIdentifierPrefix opts ++ "TOC"] $ contents'
315+ then anchor ! [href $ "#" ++ writerIdentifierPrefix opts ++ "TOC"] $ contents'
324316 else contents'
325317 return $ case level of
326318 1 -> h1 contents''
@@ -460,7 +452,7 @@ inlineToHtml opts inline =
460452 then thespan ! [theclass "math"] $ primHtml str
461453 else thediv ! [theclass "math"] $ primHtml str
462454 MimeTeX url ->
463− return $ image ! [src' (url ++ "?" ++ str),
455+ return $ image ! [src (url ++ "?" ++ str),
464456 alt str, title str]
465457 GladTeX ->
466458 return $ primHtml $ "<EQ>" ++ str ++ "</EQ>"
@@ -492,13 +484,13 @@ inlineToHtml opts inline =
492484 return $ obfuscateLink opts (show linkText) s
493485 (Link txt (s,tit)) -> do
494486 linkText <- inlineListToHtml opts txt
495− return $ anchor ! ([href' s] ++
487+ return $ anchor ! ([href s] ++
496488 if null tit then [] else [title tit]) $
497489 linkText
498490 (Image txt (s,tit)) -> do
499491 alternate <- inlineListToHtml opts txt
500492 let alternate' = renderFragment opts alternate
501− let attributes = [src' s] ++
493+ let attributes = [src s] ++
502494 (if null tit
503495 then []
504496 else [title tit]) ++
@@ -516,7 +508,7 @@ inlineToHtml opts inline =
516508 -- push contents onto front of notes
517509 put $ st {stNotes = (htmlContents:notes)}
518510 return $ sup <<
519− anchor ! [href' ("#" ++ writerIdentifierPrefix opts ++ "fn" ++ ref),
511+ anchor ! [href ("#" ++ writerIdentifierPrefix opts ++ "fn" ++ ref),
520512 theclass "footnoteRef",
521513 prefixedId opts ("fnref" ++ ref)] << ref
522514 (Cite _ il) -> inlineListToHtml opts il
@@ -525,7 +517,7 @@ blockListToNote :: WriterOptions -> String -> [Block] -> State WriterState Html
525517blockListToNote opts ref blocks =
526518 -- If last block is Para or Plain, include the backlink at the end of
527519 -- that block. Otherwise, insert a new Plain block with the backlink.
528− let backlink = [HtmlInline $ " <a href=\"#" ++ stringToURI (writerIdentifierPrefix opts ++ "fnref" ++ ref) ++
520+ let backlink = [HtmlInline $ " <a href=\"#" ++ writerIdentifierPrefix opts ++ "fnref" ++ ref ++
529521 "\" class=\"footnoteBackLink\"" ++
530522 " title=\"Jump back to footnote " ++ ref ++ "\">↩</a>"]
531523 blocks' = if null blocks