git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: do not allow closing asterisks to be followed by "*"
commita1977dd2d67e6ccbafaf7ac25f941bdd399469fa authorAlexander Krotov <ilabdsf@gmail.com> dateTue 15 Oct 2019, 16:36 (7 years ago) parenta0aeb13
2 files changed+30−5
src/Text/Pandoc/Readers/Muse.hs+7−2 test/Tests/Readers/Muse.hs+23−3
src/Text/Pandoc/Readers/Muse.hs+7−2
@@ -736,6 +736,7 @@ inline' = whitespace
736736 <|> br
737737 <|> anchor
738738 <|> footnote
739+ <|> strongEmph
739740 <|> strong
740741 <|> strongTag
741742 <|> emph
@@ -818,13 +819,17 @@ inlineTag tag = try $ mconcat
818819 <$ openTag tag
819820 <*> manyTill inline (closeTag tag)
820821
822+-- | Parse strong emphasis inline markup, indicated by @***@.
823+strongEmph :: PandocMonad m => MuseParser m (F Inlines)
824+strongEmph = fmap (B.strong . B.emph) <$> emphasisBetween (string "***" <* notFollowedBy (char '*'))
825+
821826-- | Parse strong inline markup, indicated by @**@.
822827strong :: PandocMonad m => MuseParser m (F Inlines)
823−strong = fmap B.strong <$> emphasisBetween (string "**")
828+strong = fmap B.strong <$> emphasisBetween (string "**" <* notFollowedBy (char '*'))
824829
825830-- | Parse emphasis inline markup, indicated by @*@.
826831emph :: PandocMonad m => MuseParser m (F Inlines)
827−emph = fmap B.emph <$> emphasisBetween (char '*')
832+emph = fmap B.emph <$> emphasisBetween (char '*' <* notFollowedBy (char '*'))
828833
829834-- | Parse underline inline markup, indicated by @_@.
830835-- Supported only in Emacs Muse mode, not Text::Amuse.
test/Tests/Readers/Muse.hs+23−3
@@ -139,11 +139,31 @@ tests =
139139
140140 , "Asterisk between words does not terminate emphasis" =:
141141 "*foo*bar*" =?>
142− para (emph $ "foo*bar")
142+ para (emph "foo*bar")
143143
144− , "Asterisks between words do not terminate strong" =:
144+ , "Two asterisks between words do not terminate emphasis" =:
145+ "*foo**bar*" =?>
146+ para (emph "foo**bar")
147+
148+ , "Three asterisks between words do not terminate emphasis" =:
149+ "*foo***bar*" =?>
150+ para (emph "foo***bar")
151+
152+ , "Two asterisks between words do not terminate strong" =:
145153 "**foo**bar**" =?>
146− para (strong $ "foo**bar")
154+ para (strong "foo**bar")
155+
156+ , "Three asterisks between words do not terminate strong" =:
157+ "**foo***bar**" =?>
158+ para (strong "foo***bar")
159+
160+ , "Three asterisks between words do not terminate strong emphasis" =:
161+ "***foo***bar***" =?>
162+ para (strong . emph $ "foo***bar")
163+
164+ , "Six asterisks between words do not terminate strong emphasis" =:
165+ "***foo******bar***" =?>
166+ para (strong . emph $ "foo******bar")
147167
148168 , test emacsMuse "Underline"
149169 ("_Underline_" =?> para (underlineSpan "Underline"))