@@ -322,20 +322,26 @@ containsFootnotes = p
322322 s [] = False
323323
324324-- | Return True if string should be escaped with <verbatim> tags
325−shouldEscapeString :: Bool -> String -> Bool
326−shouldEscapeString isInsideLinkDescription s =
327− any (`elem` ("#*<=|" :: String)) s ||
328− "::" `isInfixOf` s ||
329− "~~" `isInfixOf` s ||
330− "[[" `isInfixOf` s ||
331− ("]" `isInfixOf` s && isInsideLinkDescription) ||
332− containsFootnotes s
333−
334−conditionalEscapeString :: Bool -> String -> String
335−conditionalEscapeString isInsideLinkDescription s =
336− if shouldEscapeString isInsideLinkDescription s
337− then escapeString s
338− else s
325+shouldEscapeString :: PandocMonad m
326+ => String
327+ -> Muse m Bool
328+shouldEscapeString s = do
329+ insideLink <- asks envInsideLinkDescription
330+ return $ any (`elem` ("#*<=|" :: String)) s ||
331+ "::" `isInfixOf` s ||
332+ "~~" `isInfixOf` s ||
333+ "[[" `isInfixOf` s ||
334+ ("]" `isInfixOf` s && insideLink) ||
335+ containsFootnotes s
336+
337+conditionalEscapeString :: PandocMonad m
338+ => String
339+ -> Muse m String
340+conditionalEscapeString s = do
341+ shouldEscape <- shouldEscapeString s
342+ if shouldEscape
343+ then return $ escapeString s
344+ else return $ s
339345
340346-- Expand Math and Cite before normalizing inline list
341347preprocessInlineList :: PandocMonad m
@@ -459,9 +465,8 @@ inlineListToMuse' lst = do
459465inlineToMuse :: PandocMonad m
460466 => Inline
461467 -> Muse m Doc
462−inlineToMuse (Str str) = do
463− insideLink <- asks envInsideLinkDescription
464− return $ text $ conditionalEscapeString insideLink str
468+inlineToMuse (Str str) =
469+ text <$> conditionalEscapeString str
465470inlineToMuse (Emph lst) = do
466471 contents <- inlineListToMuse lst
467472 return $ "<em>" <> contents <> "</em>"
@@ -516,11 +521,12 @@ inlineToMuse (Image attr alt (source,'f':'i':'g':':':title)) =
516521inlineToMuse (Image attr@(_, classes, _) inlines (source, title)) = do
517522 opts <- asks envOptions
518523 alt <- local (\env -> env { envInsideLinkDescription = True }) $ inlineListToMuse inlines
519− let title' = if null title
520− then if null inlines
521− then ""
522− else "[" <> alt <> "]"
523− else "[" <> text (conditionalEscapeString True title) <> "]"
524+ title' <- if null title
525+ then if null inlines
526+ then return ""
527+ else return $ "[" <> alt <> "]"
528+ else do s <- local (\env -> env { envInsideLinkDescription = True }) $ conditionalEscapeString title
529+ return $ "[" <> text s <> "]"
524530 let width = case dimension Width attr of
525531 Just (Percent x) | isEnabled Ext_amuse opts -> " " ++ show (round x :: Integer)
526532 _ -> ""