git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #3904 from labdsf/muse-reader-code
4f2dd91John MacFarlane
src/Text/Pandoc/Readers/Muse.hs+6−9
@@ -575,13 +575,6 @@ enclosedInlines :: (PandocMonad m, Show a, Show b)
575enclosedInlines start end = try $
575enclosedInlines start end = try $
576 trimInlinesF . mconcat <$> enclosed start end inline
576 trimInlinesF . mconcat <$> enclosed start end inline
577
577
578−verbatimBetween :: PandocMonad m
579− => Char
580− -> MuseParser m String
581−verbatimBetween c = try $ do
582− char c
583− many1Till anyChar $ char c
584−
585inlineTag :: PandocMonad m
578inlineTag :: PandocMonad m
586 => (Inlines -> Inlines)
579 => (Inlines -> Inlines)
587 -> String
580 -> String
@@ -617,9 +610,13 @@ code = try $ do
617 sp <- if sourceColumn pos == 1
610 sp <- if sourceColumn pos == 1
618 then pure mempty
611 then pure mempty
619 else skipMany1 spaceChar >> pure B.space
612 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"
621 notFollowedBy nonspaceChar
618 notFollowedBy nonspaceChar
622− return $ return (sp B.<> B.code cd)
619+ return $ return (sp B.<> B.code contents)
623
620
624codeTag :: PandocMonad m => MuseParser m (F Inlines)
621codeTag :: PandocMonad m => MuseParser m (F Inlines)
625codeTag = do
622codeTag = do
test/Tests/Readers/Muse.hs+32−2
@@ -72,9 +72,39 @@ tests =
72
72
73 , "Linebreak" =: "Line <br> break" =?> para ("Line" <> linebreak <> "break")
73 , "Linebreak" =: "Line <br> break" =?> para ("Line" <> linebreak <> "break")
74
74
75+ , testGroup "Code markup"
75− , "Code" =: "=foo(bar)=" =?> para (code "foo(bar)")
76+ [ "Code" =: "=foo(bar)=" =?> para (code "foo(bar)")
76
77
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+ ]
78
108
79 , "Code tag" =: "<code>foo(bar)</code>" =?> para (code "foo(bar)")
109 , "Code tag" =: "<code>foo(bar)</code>" =?> para (code "foo(bar)")
80
110