diff --git a/src/Text/Pandoc/Writers/ICML.hs b/src/Text/Pandoc/Writers/ICML.hs index f42d26614..08e3e5b63 100644 --- a/src/Text/Pandoc/Writers/ICML.hs +++ b/src/Text/Pandoc/Writers/ICML.hs @@ -251,6 +251,13 @@ charStylesToDoc st = vcat $ map makeStyle $ Set.toAscList $ inlineStyles st else empty in inTags True "CharacterStyle" ([("Self", "CharacterStyle/"++s), ("Name", s)] ++ attrs') props +-- | Escape colon characters as %3a +escapeColons :: String -> String +escapeColons (x:xs) + | x == ':' = "%3a" ++ escapeColons xs + | otherwise = x : escapeColons xs +escapeColons [] = [] + -- | Convert a list of (identifier, url) pairs to the ICML listing of hyperlinks. hyperlinksToDoc :: Hyperlink -> Doc hyperlinksToDoc [] = empty @@ -259,13 +266,13 @@ hyperlinksToDoc (x:xs) = hyp x $$ hyperlinksToDoc xs hyp (ident, url) = hdest $$ hlink where hdest = selfClosingTag "HyperlinkURLDestination" - [("Self", "HyperlinkURLDestination/"++url), ("Name","link"), ("DestinationURL",url), ("DestinationUniqueKey","1")] + [("Self", "HyperlinkURLDestination/"++(escapeColons url)), ("Name","link"), ("DestinationURL",url), ("DestinationUniqueKey","1")] -- HyperlinkURLDestination with more than one colon crashes CS6 hlink = inTags True "Hyperlink" [("Self","uf-"++show ident), ("Name",url), ("Source","htss-"++show ident), ("Visible","true"), ("DestinationUniqueKey","1")] $ inTags True "Properties" [] $ inTags False "BorderColor" [("type","enumeration")] (text "Black") $$ (inTags False "Destination" [("type","object")] - $ text $ "HyperlinkURLDestination/"++(escapeStringForXML url)) + $ text $ "HyperlinkURLDestination/"++(escapeColons (escapeStringForXML url))) -- HyperlinkURLDestination with more than one colon crashes CS6 -- | Convert a list of Pandoc blocks to ICML. diff --git a/tests/writer.icml b/tests/writer.icml index 26795df58..b6f5b5e32 100644 --- a/tests/writer.icml +++ b/tests/writer.icml @@ -2717,39 +2717,39 @@ These should not be escaped: \$ \\ \> \[ \{ - + Black - HyperlinkURLDestination/http://google.com + HyperlinkURLDestination/http%3a//google.com - + Black - HyperlinkURLDestination/http://example.com/ + HyperlinkURLDestination/http%3a//example.com/ - + Black - HyperlinkURLDestination/mailto:nobody@nowhere.net + HyperlinkURLDestination/mailto%3anobody@nowhere.net - + Black - HyperlinkURLDestination/http://example.com/ + HyperlinkURLDestination/http%3a//example.com/ - + Black - HyperlinkURLDestination/http://example.com/?foo=1&bar=2 + HyperlinkURLDestination/http%3a//example.com/?foo=1&bar=2 @@ -2766,18 +2766,18 @@ These should not be escaped: \$ \\ \> \[ \{ HyperlinkURLDestination//script?foo=1&bar=2 - + Black - HyperlinkURLDestination/http://att.com/ + HyperlinkURLDestination/http%3a//att.com/ - + Black - HyperlinkURLDestination/http://example.com/?foo=1&bar=2 + HyperlinkURLDestination/http%3a//example.com/?foo=1&bar=2 @@ -2857,11 +2857,11 @@ These should not be escaped: \$ \\ \> \[ \{ HyperlinkURLDestination/ - + Black - HyperlinkURLDestination/mailto:nobody@nowhere.net + HyperlinkURLDestination/mailto%3anobody@nowhere.net @@ -2913,11 +2913,11 @@ These should not be escaped: \$ \\ \> \[ \{ HyperlinkURLDestination//url/ - + Black - HyperlinkURLDestination/http://example.com/?foo=1&bar=2 + HyperlinkURLDestination/http%3a//example.com/?foo=1&bar=2