git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: expand math before inline list normalization
7da6e43Alexander Krotov
src/Text/Pandoc/Writers/Muse.hs+13−3
@@ -291,6 +291,14 @@ conditionalEscapeString s =
291 then escapeString s
291 then escapeString s
292 else s
292 else s
293
293
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+
294normalizeInlineList :: [Inline] -> [Inline]
302normalizeInlineList :: [Inline] -> [Inline]
295normalizeInlineList (x : Str "" : xs)
303normalizeInlineList (x : Str "" : xs)
296 = normalizeInlineList (x:xs)
304 = normalizeInlineList (x:xs)
@@ -327,7 +335,9 @@ fixNotes (x:xs) = x : fixNotes xs
327inlineListToMuse :: PandocMonad m
335inlineListToMuse :: PandocMonad m
328 => [Inline]
336 => [Inline]
329 -> StateT WriterState m Doc
337 -> StateT WriterState m Doc
338+inlineListToMuse lst = do
339+ lst' <- preprocessInlineList lst
330−inlineListToMuse lst = hcat <$> mapM inlineToMuse (fixNotes $ normalizeInlineList lst)
340+ hcat <$> mapM inlineToMuse (fixNotes $ normalizeInlineList lst')
331
341
332-- | Convert Pandoc inline element to Muse.
342-- | Convert Pandoc inline element to Muse.
333inlineToMuse :: PandocMonad m
343inlineToMuse :: PandocMonad m
@@ -363,8 +373,8 @@ inlineToMuse (Quoted DoubleQuote lst) = do
363inlineToMuse (Cite _ lst) = inlineListToMuse lst
373inlineToMuse (Cite _ lst) = inlineListToMuse lst
364inlineToMuse (Code _ str) = return $
374inlineToMuse (Code _ str) = return $
365 "<code>" <> text (substitute "</code>" "<</code><code>/code>" str) <> "</code>"
375 "<code>" <> text (substitute "</code>" "<</code><code>/code>" str) <> "</code>"
366−inlineToMuse (Math t str) =
376+inlineToMuse Math{} =
367− lift (texMathToInlines t str) >>= inlineListToMuse
377+ fail "Math should be expanded before normalization"
368inlineToMuse (RawInline (Format f) str) =
378inlineToMuse (RawInline (Format f) str) =
369 return $ "<literal style=\"" <> text f <> "\">" <> text str <> "</literal>"
379 return $ "<literal style=\"" <> text f <> "\">" <> text str <> "</literal>"
370inlineToMuse LineBreak = return $ "<br>" <> cr
380inlineToMuse LineBreak = return $ "<br>" <> cr
test/Tests/Writers/Muse.hs+1
@@ -332,6 +332,7 @@ tests = [ testGroup "block elements"
332 [ "inline math" =: math "2^3" =?> "2<sup>3</sup>"
332 [ "inline math" =: math "2^3" =?> "2<sup>3</sup>"
333 , "display math" =: displayMath "2^3" =?> "2<sup>3</sup>"
333 , "display math" =: displayMath "2^3" =?> "2<sup>3</sup>"
334 , "multiple letters in inline math" =: math "abc" =?> "<em>abc</em>"
334 , "multiple letters in inline math" =: math "abc" =?> "<em>abc</em>"
335+ , "expand math before normalization" =: math "[" <> str "2]" =?> "<verbatim>[2]</verbatim>"
335 ]
336 ]
336 , "raw inline"
337 , "raw inline"
337 =: rawInline "html" "<mark>marked text</mark>"
338 =: rawInline "html" "<mark>marked text</mark>"