git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: debug inline code markup
commit2230371304f299ca7333af8ad0ee7bcd099a4aa0 authorAlexander Krotov <ilabdsf@gmail.com> dateSat 9 Sep 2017, 11:51 (9 years ago) parent2358229
2 files changed+38−11
src/Text/Pandoc/Readers/Muse.hs+6−9 test/Tests/Readers/Muse.hs+32−2
src/Text/Pandoc/Readers/Muse.hs+6−9
@@ -575,13 +575,6 @@ enclosedInlines :: (PandocMonad m, Show a, Show b)
575575enclosedInlines start end = try $
576576 trimInlinesF . mconcat <$> enclosed start end inline
577577
578−verbatimBetween :: PandocMonad m
579− => Char
580− -> MuseParser m String
581−verbatimBetween c = try $ do
582− char c
583− many1Till anyChar $ char c
584−
585578inlineTag :: PandocMonad m
586579 => (Inlines -> Inlines)
587580 -> String
@@ -617,9 +610,13 @@ code = try $ do
617610 sp <- if sourceColumn pos == 1
618611 then pure mempty
619612 else skipMany1 spaceChar >> pure B.space
620− cd <- verbatimBetween '='
613+ char '='
614+ contents <- many1Till (noneOf "\n\r" <|> (newline <* notFollowedBy newline)) $ char '='
615+ guard $ not $ null contents
616+ guard $ head contents `notElem` " \t\n"
617+ guard $ last contents `notElem` " \t\n"
621618 notFollowedBy nonspaceChar
622− return $ return (sp B.<> B.code cd)
619+ return $ return (sp B.<> B.code contents)
623620
624621codeTag :: PandocMonad m => MuseParser m (F Inlines)
625622codeTag = do
test/Tests/Readers/Muse.hs+32−2
@@ -72,9 +72,39 @@ tests =
7272
7373 , "Linebreak" =: "Line <br> break" =?> para ("Line" <> linebreak <> "break")
7474
75− , "Code" =: "=foo(bar)=" =?> para (code "foo(bar)")
75+ , testGroup "Code markup"
76+ [ "Code" =: "=foo(bar)=" =?> para (code "foo(bar)")
7677
77− , "Not code" =: "a=b= =c=d" =?> para (text "a=b= =c=d")
78+ , "Not code" =: "a=b= =c=d" =?> para (text "a=b= =c=d")
79+
80+ -- Emacs Muse 3.20 parses this as code, we follow Amusewiki
81+ , "Not code if closing = is detached" =: "=this is not a code =" =?> para "=this is not a code ="
82+
83+ , "Not code if opening = is detached" =: "= this is not a code=" =?> para "= this is not a code="
84+
85+ , "One character code" =: "=c=" =?> para (code "c")
86+
87+ , "Three = characters is not a code" =: "===" =?> para "==="
88+
89+ , "Multiline code markup" =:
90+ "foo =bar\nbaz= end of code" =?>
91+ para (text "foo " <> code "bar\nbaz" <> text " end of code")
92+
93+{- Emacs Muse 3.20 has a bug: it publishes
94+ - <p>foo <code>bar
95+ -
96+ - baz</code> foo</p>
97+ - which is displayed as one paragraph by browsers.
98+ - We follow Amusewiki here and avoid joining paragraphs.
99+ -}
100+ , "No multiparagraph code" =:
101+ T.unlines [ "foo =bar"
102+ , ""
103+ , "baz= foo"
104+ ] =?>
105+ para "foo =bar" <>
106+ para "baz= foo"
107+ ]
78108
79109 , "Code tag" =: "<code>foo(bar)</code>" =?> para (code "foo(bar)")
80110