git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: wrap conditionalEscapeString result into "Muse" type
db44ddfAlexander Krotov
src/Text/Pandoc/Writers/Muse.hs+28−22
@@ -322,20 +322,26 @@ containsFootnotes = p
322 s [] = False
322 s [] = False
323
323
324-- | Return True if string should be escaped with <verbatim> tags
324-- | Return True if string should be escaped with <verbatim> tags
325−shouldEscapeString :: Bool -> String -> Bool
325+shouldEscapeString :: PandocMonad m
326+ => String
327+ -> Muse m Bool
326−shouldEscapeString isInsideLinkDescription s =
328+shouldEscapeString s = do
329+ insideLink <- asks envInsideLinkDescription
327− any (`elem` ("#*<=|" :: String)) s ||
330+ return $ any (`elem` ("#*<=|" :: String)) s ||
328− "::" `isInfixOf` s ||
331+ "::" `isInfixOf` s ||
329− "~~" `isInfixOf` s ||
332+ "~~" `isInfixOf` s ||
330− "[[" `isInfixOf` s ||
333+ "[[" `isInfixOf` s ||
331− ("]" `isInfixOf` s && isInsideLinkDescription) ||
334+ ("]" `isInfixOf` s && insideLink) ||
332− containsFootnotes s
335+ containsFootnotes s
333−
336+
334−conditionalEscapeString :: Bool -> String -> String
337+conditionalEscapeString :: PandocMonad m
338+ => String
339+ -> Muse m String
335−conditionalEscapeString isInsideLinkDescription s =
340+conditionalEscapeString s = do
336− if shouldEscapeString isInsideLinkDescription s
341+ shouldEscape <- shouldEscapeString s
342+ if shouldEscape
337− then escapeString s
343+ then return $ escapeString s
338− else s
344+ else return $ s
339
345
340-- Expand Math and Cite before normalizing inline list
346-- Expand Math and Cite before normalizing inline list
341preprocessInlineList :: PandocMonad m
347preprocessInlineList :: PandocMonad m
@@ -459,9 +465,8 @@ inlineListToMuse' lst = do
459inlineToMuse :: PandocMonad m
465inlineToMuse :: PandocMonad m
460 => Inline
466 => Inline
461 -> Muse m Doc
467 -> Muse m Doc
462−inlineToMuse (Str str) = do
468+inlineToMuse (Str str) =
463− insideLink <- asks envInsideLinkDescription
464− return $ text $ conditionalEscapeString insideLink str
469+ text <$> conditionalEscapeString str
465inlineToMuse (Emph lst) = do
470inlineToMuse (Emph lst) = do
466 contents <- inlineListToMuse lst
471 contents <- inlineListToMuse lst
467 return $ "<em>" <> contents <> "</em>"
472 return $ "<em>" <> contents <> "</em>"
@@ -516,11 +521,12 @@ inlineToMuse (Image attr alt (source,'f':'i':'g':':':title)) =
516inlineToMuse (Image attr@(_, classes, _) inlines (source, title)) = do
521inlineToMuse (Image attr@(_, classes, _) inlines (source, title)) = do
517 opts <- asks envOptions
522 opts <- asks envOptions
518 alt <- local (\env -> env { envInsideLinkDescription = True }) $ inlineListToMuse inlines
523 alt <- local (\env -> env { envInsideLinkDescription = True }) $ inlineListToMuse inlines
519− let title' = if null title
524+ title' <- if null title
520− then if null inlines
525+ then if null inlines
521− then ""
526+ then return ""
522− else "[" <> alt <> "]"
527+ else return $ "[" <> alt <> "]"
523− else "[" <> text (conditionalEscapeString True title) <> "]"
528+ else do s <- local (\env -> env { envInsideLinkDescription = True }) $ conditionalEscapeString title
529+ return $ "[" <> text s <> "]"
524 let width = case dimension Width attr of
530 let width = case dimension Width attr of
525 Just (Percent x) | isEnabled Ext_amuse opts -> " " ++ show (round x :: Integer)
531 Just (Percent x) | isEnabled Ext_amuse opts -> " " ++ show (round x :: Integer)
526 _ -> ""
532 _ -> ""