aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorAlexander Krotov <ilabdsf@gmail.com>2018-03-20 11:15:43 +0300
committerAlexander Krotov <ilabdsf@gmail.com>2018-03-20 12:16:34 +0300
commitd63bba30661182f15e56d07997ee0f7b539eb2ce (patch)
tree008e5a36fbfda98eb8b7097eaff4895833e465bc /src/Text
parent43677682d87824cf21b55dbc867a9e866b8296b4 (diff)
downloadpandoc-d63bba30661182f15e56d07997ee0f7b539eb2ce.tar.gz
Muse writer: escape "]" brackets in URLs as "%5D"
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/Muse.hs9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/Muse.hs b/src/Text/Pandoc/Writers/Muse.hs
index 2d53ca9a1..e72fcf52b 100644
--- a/src/Text/Pandoc/Writers/Muse.hs
+++ b/src/Text/Pandoc/Writers/Muse.hs
@@ -345,6 +345,11 @@ fixNotes (Space : n@Note{} : rest) = Str " " : n : fixNotes rest
fixNotes (SoftBreak : n@Note{} : rest) = Str " " : n : fixNotes rest
fixNotes (x:xs) = x : fixNotes xs
+urlEscapeBrackets :: String -> String
+urlEscapeBrackets (']':xs) = '%':'5':'D':urlEscapeBrackets xs
+urlEscapeBrackets (x:xs) = x:urlEscapeBrackets xs
+urlEscapeBrackets [] = []
+
-- | Convert list of Pandoc inline elements to Muse.
inlineListToMuse :: PandocMonad m
=> [Inline]
@@ -402,7 +407,7 @@ inlineToMuse (Link _ txt (src, _)) =
return $ "[[" <> text (escapeLink x) <> "]]"
_ -> do contents <- inlineListToMuse txt
return $ "[[" <> text (escapeLink src) <> "][" <> contents <> "]]"
- where escapeLink lnk = if isImageUrl lnk then "URL:" ++ lnk else lnk
+ where escapeLink lnk = if isImageUrl lnk then "URL:" ++ urlEscapeBrackets lnk else urlEscapeBrackets lnk
-- Taken from muse-image-regexp defined in Emacs Muse file lisp/muse-regexps.el
imageExtensions = [".eps", ".gif", ".jpg", ".jpeg", ".pbm", ".png", ".tiff", ".xbm", ".xpm"]
isImageUrl = (`elem` imageExtensions) . takeExtension
@@ -419,7 +424,7 @@ inlineToMuse (Image attr inlines (source, title)) = do
let width = case dimension Width attr of
Just (Percent x) | isEnabled Ext_amuse opts -> " " ++ show (round x :: Integer)
_ -> ""
- return $ "[[" <> text (source ++ width) <> "]" <> title' <> "]"
+ return $ "[[" <> text (urlEscapeBrackets source ++ width) <> "]" <> title' <> "]"
inlineToMuse (Note contents) = do
-- add to notes in state
notes <- gets stNotes