git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: expand math before inline list normalization
commit7da6e4390cb6d812b67dca6720bb56f3963c05d5 authorAlexander Krotov <ilabdsf@gmail.com> dateMon 5 Mar 2018, 19:38 (9 years ago) parent7518e8e
2 files changed+14−3
src/Text/Pandoc/Writers/Muse.hs+13−3 test/Tests/Writers/Muse.hs+1
src/Text/Pandoc/Writers/Muse.hs+13−3
@@ -291,6 +291,14 @@ conditionalEscapeString s =
291291 then escapeString s
292292 else s
293293
294+-- Expand Math before normalizing inline list
295+preprocessInlineList :: PandocMonad m
296+ => [Inline]
297+ -> m [Inline]
298+preprocessInlineList (Math t str:xs) = (++ xs) <$> texMathToInlines t str
299+preprocessInlineList (x:xs) = (x:) <$> preprocessInlineList xs
300+preprocessInlineList [] = return []
301+
294302normalizeInlineList :: [Inline] -> [Inline]
295303normalizeInlineList (x : Str "" : xs)
296304 = normalizeInlineList (x:xs)
@@ -327,7 +335,9 @@ fixNotes (x:xs) = x : fixNotes xs
327335inlineListToMuse :: PandocMonad m
328336 => [Inline]
329337 -> StateT WriterState m Doc
330−inlineListToMuse lst = hcat <$> mapM inlineToMuse (fixNotes $ normalizeInlineList lst)
338+inlineListToMuse lst = do
339+ lst' <- preprocessInlineList lst
340+ hcat <$> mapM inlineToMuse (fixNotes $ normalizeInlineList lst')
331341
332342-- | Convert Pandoc inline element to Muse.
333343inlineToMuse :: PandocMonad m
@@ -363,8 +373,8 @@ inlineToMuse (Quoted DoubleQuote lst) = do
363373inlineToMuse (Cite _ lst) = inlineListToMuse lst
364374inlineToMuse (Code _ str) = return $
365375 "<code>" <> text (substitute "</code>" "<</code><code>/code>" str) <> "</code>"
366−inlineToMuse (Math t str) =
367− lift (texMathToInlines t str) >>= inlineListToMuse
376+inlineToMuse Math{} =
377+ fail "Math should be expanded before normalization"
368378inlineToMuse (RawInline (Format f) str) =
369379 return $ "<literal style=\"" <> text f <> "\">" <> text str <> "</literal>"
370380inlineToMuse LineBreak = return $ "<br>" <> cr
test/Tests/Writers/Muse.hs+1
@@ -332,6 +332,7 @@ tests = [ testGroup "block elements"
332332 [ "inline math" =: math "2^3" =?> "2<sup>3</sup>"
333333 , "display math" =: displayMath "2^3" =?> "2<sup>3</sup>"
334334 , "multiple letters in inline math" =: math "abc" =?> "<em>abc</em>"
335+ , "expand math before normalization" =: math "[" <> str "2]" =?> "<verbatim>[2]</verbatim>"
335336 ]
336337 , "raw inline"
337338 =: rawInline "html" "<mark>marked text</mark>"