git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: use tags instead of lightweight markup for empty strings
commitc2b97c4b8026694d9c59d7b9f6d333d204f669ce authorAlexander Krotov <ilabdsf@gmail.com> dateTue 11 Sep 2018, 00:38 (8 years ago) parent7b52d43
2 files changed+13−4
src/Text/Pandoc/Writers/Muse.hs+9−4 test/Tests/Writers/Muse.hs+4
src/Text/Pandoc/Writers/Muse.hs+9−4
@@ -420,6 +420,11 @@ endsWithSpace [SoftBreak] = True
420420endsWithSpace (_:xs) = endsWithSpace xs
421421endsWithSpace [] = False
422422
423+emptyInlines :: [Inline] -> Bool
424+emptyInlines [] = True
425+emptyInlines (Str "":xs) = emptyInlines xs
426+emptyInlines _ = False
427+
423428urlEscapeBrackets :: String -> String
424429urlEscapeBrackets (']':xs) = '%':'5':'D':urlEscapeBrackets xs
425430urlEscapeBrackets (x:xs) = x:urlEscapeBrackets xs
@@ -517,7 +522,7 @@ inlineToMuse (Emph [Strong lst]) = do
517522 then do contents <- local (\env -> env { envInsideAsterisks = True }) $ inlineListToMuse lst
518523 modify $ \st -> st { stUseTags = False }
519524 return $ "<em>**" <> contents <> "**</em>"
520− else if null lst || startsWithSpace lst || endsWithSpace lst
525+ else if emptyInlines lst || startsWithSpace lst || endsWithSpace lst
521526 then do
522527 contents <- local (\env -> env { envInsideAsterisks = False }) $ inlineListToMuse lst
523528 modify $ \st -> st { stUseTags = True }
@@ -528,7 +533,7 @@ inlineToMuse (Emph [Strong lst]) = do
528533 return $ "***" <> contents <> "***"
529534inlineToMuse (Emph lst) = do
530535 useTags <- gets stUseTags
531− if useTags || null lst || startsWithSpace lst || endsWithSpace lst
536+ if useTags || emptyInlines lst || startsWithSpace lst || endsWithSpace lst
532537 then do contents <- inlineListToMuse lst
533538 return $ "<em>" <> contents <> "</em>"
534539 else do contents <- local (\env -> env { envInsideAsterisks = True }) $ inlineListToMuse lst
@@ -540,7 +545,7 @@ inlineToMuse (Strong [Emph lst]) = do
540545 then do contents <- local (\env -> env { envInsideAsterisks = True }) $ inlineListToMuse lst
541546 modify $ \st -> st { stUseTags = False }
542547 return $ "<strong>*" <> contents <> "*</strong>"
543− else if null lst || startsWithSpace lst || endsWithSpace lst
548+ else if emptyInlines lst || startsWithSpace lst || endsWithSpace lst
544549 then do
545550 contents <- local (\env -> env { envInsideAsterisks = False }) $ inlineListToMuse lst
546551 modify $ \st -> st { stUseTags = True }
@@ -551,7 +556,7 @@ inlineToMuse (Strong [Emph lst]) = do
551556 return $ "***" <> contents <> "***"
552557inlineToMuse (Strong lst) = do
553558 useTags <- gets stUseTags
554− if useTags || null lst || startsWithSpace lst || endsWithSpace lst
559+ if useTags || emptyInlines lst || startsWithSpace lst || endsWithSpace lst
555560 then do contents <- inlineListToMuse lst
556561 modify $ \st -> st { stUseTags = False }
557562 return $ "<strong>" <> contents <> "</strong>"
test/Tests/Writers/Muse.hs+4
@@ -362,6 +362,10 @@ tests = [ testGroup "block elements"
362362 , "empty strong" =: strong mempty =?> "<strong></strong>"
363363 , "empty strong emphasis" =: strong (emph mempty) =?> "**<em></em>**"
364364 , "empty emphasized strong" =: emph (strong mempty) =?> "*<strong></strong>*"
365+ , "emphasized empty string" =: emph (str "") =?> "<em></em>"
366+ , "strong empty string" =: strong (str "") =?> "<strong></strong>"
367+ , "strong emphasized empty string" =: strong (emph (str "")) =?> "**<em></em>**"
368+ , "emphasized strong empty string" =: emph (strong (str "")) =?> "*<strong></strong>*"
365369 , "strong" =: strong (text "foo") =?> "**foo**"
366370 , "strong inside word" =: text "foo" <> strong (text "bar") <> text "baz" =?> "foo<strong>bar</strong>baz"
367371 , "strong emphasis" =: strong (emph (text "foo")) =?> "***foo***"