From 4a8993f9b008a0ff223b5a1e283ae9e21a66c5c0 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Sun, 25 Mar 2018 01:18:33 +0300 Subject: [PATCH] Muse writer: improve span writing Test more cases when span has or hasn't anchor, class and contents in different combinations. --- src/Text/Pandoc/Writers/Muse.hs | 8 +++++--- test/Tests/Writers/Muse.hs | 10 ++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Text/Pandoc/Writers/Muse.hs b/src/Text/Pandoc/Writers/Muse.hs index 6ecd826fa..128e2c6f9 100644 --- a/src/Text/Pandoc/Writers/Muse.hs +++ b/src/Text/Pandoc/Writers/Muse.hs @@ -441,6 +441,8 @@ inlineToMuse (Span (anchor,names,_) inlines) = do let anchorDoc = if null anchor then mempty else text ('#':anchor) <> space - return $ anchorDoc <> if null names - then contents - else " text (head names) <> "\">" <> contents <> "" + return $ anchorDoc <> (if null inlines && not (null anchor) + then mempty + else (if null names + then "" + else " text (head names) <> "\">") <> contents <> "") diff --git a/test/Tests/Writers/Muse.hs b/test/Tests/Writers/Muse.hs index 1218bc7c9..c3a6a9d62 100644 --- a/test/Tests/Writers/Muse.hs +++ b/test/Tests/Writers/Muse.hs @@ -400,9 +400,15 @@ tests = [ testGroup "block elements" , "[1] Foo" ] , "span with class" =: spanWith ("",["foobar"],[]) (text "Some text") - =?> "Some text" - , "span with anchor" =: spanWith ("anchor", [], []) (text "Foo bar") + =?> "Some text" + , "span without class" =: spanWith ("",[],[]) (text "Some text") + =?> "Some text" + , "span with anchor" =: spanWith ("anchor", [], []) (mempty) <> (text "Foo bar") =?> "#anchor Foo bar" + , "empty span with anchor" =: spanWith ("anchor", [], []) (mempty) + =?> "#anchor" + , "empty span without class and anchor" =: spanWith ("", [], []) (mempty) + =?> "" , "span with class and anchor" =: spanWith ("anchor", ["foo"], []) (text "bar") =?> "#anchor bar" , "adjacent spans" =: spanWith ("", ["syllable"], []) (str "wa") <>