git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: use tags instead of lightweight markup for empty strings
c2b97c4Alexander Krotov
src/Text/Pandoc/Writers/Muse.hs+9−4
@@ -420,6 +420,11 @@ endsWithSpace [SoftBreak] = True
420endsWithSpace (_:xs) = endsWithSpace xs
420endsWithSpace (_:xs) = endsWithSpace xs
421endsWithSpace [] = False
421endsWithSpace [] = False
422
422
423+emptyInlines :: [Inline] -> Bool
424+emptyInlines [] = True
425+emptyInlines (Str "":xs) = emptyInlines xs
426+emptyInlines _ = False
427+
423urlEscapeBrackets :: String -> String
428urlEscapeBrackets :: String -> String
424urlEscapeBrackets (']':xs) = '%':'5':'D':urlEscapeBrackets xs
429urlEscapeBrackets (']':xs) = '%':'5':'D':urlEscapeBrackets xs
425urlEscapeBrackets (x:xs) = x:urlEscapeBrackets xs
430urlEscapeBrackets (x:xs) = x:urlEscapeBrackets xs
@@ -517,7 +522,7 @@ inlineToMuse (Emph [Strong lst]) = do
517 then do contents <- local (\env -> env { envInsideAsterisks = True }) $ inlineListToMuse lst
522 then do contents <- local (\env -> env { envInsideAsterisks = True }) $ inlineListToMuse lst
518 modify $ \st -> st { stUseTags = False }
523 modify $ \st -> st { stUseTags = False }
519 return $ "<em>**" <> contents <> "**</em>"
524 return $ "<em>**" <> contents <> "**</em>"
520− else if null lst || startsWithSpace lst || endsWithSpace lst
525+ else if emptyInlines lst || startsWithSpace lst || endsWithSpace lst
521 then do
526 then do
522 contents <- local (\env -> env { envInsideAsterisks = False }) $ inlineListToMuse lst
527 contents <- local (\env -> env { envInsideAsterisks = False }) $ inlineListToMuse lst
523 modify $ \st -> st { stUseTags = True }
528 modify $ \st -> st { stUseTags = True }
@@ -528,7 +533,7 @@ inlineToMuse (Emph [Strong lst]) = do
528 return $ "***" <> contents <> "***"
533 return $ "***" <> contents <> "***"
529inlineToMuse (Emph lst) = do
534inlineToMuse (Emph lst) = do
530 useTags <- gets stUseTags
535 useTags <- gets stUseTags
531− if useTags || null lst || startsWithSpace lst || endsWithSpace lst
536+ if useTags || emptyInlines lst || startsWithSpace lst || endsWithSpace lst
532 then do contents <- inlineListToMuse lst
537 then do contents <- inlineListToMuse lst
533 return $ "<em>" <> contents <> "</em>"
538 return $ "<em>" <> contents <> "</em>"
534 else do contents <- local (\env -> env { envInsideAsterisks = True }) $ inlineListToMuse lst
539 else do contents <- local (\env -> env { envInsideAsterisks = True }) $ inlineListToMuse lst
@@ -540,7 +545,7 @@ inlineToMuse (Strong [Emph lst]) = do
540 then do contents <- local (\env -> env { envInsideAsterisks = True }) $ inlineListToMuse lst
545 then do contents <- local (\env -> env { envInsideAsterisks = True }) $ inlineListToMuse lst
541 modify $ \st -> st { stUseTags = False }
546 modify $ \st -> st { stUseTags = False }
542 return $ "<strong>*" <> contents <> "*</strong>"
547 return $ "<strong>*" <> contents <> "*</strong>"
543− else if null lst || startsWithSpace lst || endsWithSpace lst
548+ else if emptyInlines lst || startsWithSpace lst || endsWithSpace lst
544 then do
549 then do
545 contents <- local (\env -> env { envInsideAsterisks = False }) $ inlineListToMuse lst
550 contents <- local (\env -> env { envInsideAsterisks = False }) $ inlineListToMuse lst
546 modify $ \st -> st { stUseTags = True }
551 modify $ \st -> st { stUseTags = True }
@@ -551,7 +556,7 @@ inlineToMuse (Strong [Emph lst]) = do
551 return $ "***" <> contents <> "***"
556 return $ "***" <> contents <> "***"
552inlineToMuse (Strong lst) = do
557inlineToMuse (Strong lst) = do
553 useTags <- gets stUseTags
558 useTags <- gets stUseTags
554− if useTags || null lst || startsWithSpace lst || endsWithSpace lst
559+ if useTags || emptyInlines lst || startsWithSpace lst || endsWithSpace lst
555 then do contents <- inlineListToMuse lst
560 then do contents <- inlineListToMuse lst
556 modify $ \st -> st { stUseTags = False }
561 modify $ \st -> st { stUseTags = False }
557 return $ "<strong>" <> contents <> "</strong>"
562 return $ "<strong>" <> contents <> "</strong>"
test/Tests/Writers/Muse.hs+4
@@ -362,6 +362,10 @@ tests = [ testGroup "block elements"
362 , "empty strong" =: strong mempty =?> "<strong></strong>"
362 , "empty strong" =: strong mempty =?> "<strong></strong>"
363 , "empty strong emphasis" =: strong (emph mempty) =?> "**<em></em>**"
363 , "empty strong emphasis" =: strong (emph mempty) =?> "**<em></em>**"
364 , "empty emphasized strong" =: emph (strong mempty) =?> "*<strong></strong>*"
364 , "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>*"
365 , "strong" =: strong (text "foo") =?> "**foo**"
369 , "strong" =: strong (text "foo") =?> "**foo**"
366 , "strong inside word" =: text "foo" <> strong (text "bar") <> text "baz" =?> "foo<strong>bar</strong>baz"
370 , "strong inside word" =: text "foo" <> strong (text "bar") <> text "baz" =?> "foo<strong>bar</strong>baz"
367 , "strong emphasis" =: strong (emph (text "foo")) =?> "***foo***"
371 , "strong emphasis" =: strong (emph (text "foo")) =?> "***foo***"