git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: escape "]" in image title
81afcdfAlexander Krotov
src/Text/Pandoc/Writers/Muse.hs+2−1
@@ -428,11 +428,12 @@ inlineToMuse (Image attr inlines (source, title)) = do
428 then if null inlines
428 then if null inlines
429 then ""
429 then ""
430 else "[" <> alt <> "]"
430 else "[" <> alt <> "]"
431− else "[" <> text title <> "]"
431+ else "[" <> text (escape title) <> "]"
432 let width = case dimension Width attr of
432 let width = case dimension Width attr of
433 Just (Percent x) | isEnabled Ext_amuse opts -> " " ++ show (round x :: Integer)
433 Just (Percent x) | isEnabled Ext_amuse opts -> " " ++ show (round x :: Integer)
434 _ -> ""
434 _ -> ""
435 return $ "[[" <> text (urlEscapeBrackets source ++ width) <> "]" <> title' <> "]"
435 return $ "[[" <> text (urlEscapeBrackets source ++ width) <> "]" <> title' <> "]"
436+ where escape s = if "]" `isInfixOf` s then escapeString s else conditionalEscapeString s
436inlineToMuse (Note contents) = do
437inlineToMuse (Note contents) = do
437 -- add to notes in state
438 -- add to notes in state
438 notes <- gets stNotes
439 notes <- gets stNotes
test/Tests/Writers/Muse.hs+1
@@ -393,6 +393,7 @@ tests = [ testGroup "block elements"
393 , "image with width" =:
393 , "image with width" =:
394 imageWith ("", [], [("width", "60%")]) "image.png" "Image" (str "") =?>
394 imageWith ("", [], [("width", "60%")]) "image.png" "Image" (str "") =?>
395 "[[image.png 60][Image]]"
395 "[[image.png 60][Image]]"
396+ , "escape brackets in image title" =: image "image.png" "Foo]bar" (str "") =?> "[[image.png][<verbatim>Foo]bar</verbatim>]]"
396 , "note" =: note (plain (text "Foo"))
397 , "note" =: note (plain (text "Foo"))
397 =?> unlines [ "[1]"
398 =?> unlines [ "[1]"
398 , ""
399 , ""