git.iko.soy/typeable/pandoc
on master help sign in
MediaWiki reader: Trim contents of `<math>` tags.

Otherwise we get problems when converting to markdown. Closes #1027.

commite5feed00f7edb0d79f717ec9815c57df696a992e authorJohn MacFarlane <jgm@berkeley.edu> dateFri 18 Oct 2013, 17:50 (13 years ago) parent1f29f46
3 files changed+8−5
src/Text/Pandoc/Readers/MediaWiki.hs+5−5 tests/mediawiki-reader.native+1 tests/mediawiki-reader.wiki+2
src/Text/Pandoc/Readers/MediaWiki.hs+5−5
@@ -43,7 +43,7 @@ import Text.Pandoc.Readers.HTML ( htmlTag, isBlockTag, isCommentTag )
4343import Text.Pandoc.XML ( fromEntities )
4444import Text.Pandoc.Parsing hiding ( nested )
4545import Text.Pandoc.Walk ( walk )
46−import Text.Pandoc.Shared ( stripTrailingNewlines, safeRead, stringify )
46+import Text.Pandoc.Shared ( stripTrailingNewlines, safeRead, stringify, trim )
4747import Data.Monoid (mconcat, mempty)
4848import Control.Applicative ((<$>), (<*), (*>), (<$))
4949import Control.Monad
@@ -475,10 +475,10 @@ str :: MWParser Inlines
475475str = B.str <$> many1 (noneOf $ specialChars ++ spaceChars)
476476
477477math :: MWParser Inlines
478−math = (B.displayMath <$> try (char ':' >> charsInTags "math"))
479− <|> (B.math <$> charsInTags "math")
480− <|> (B.displayMath <$> try (dmStart *> manyTill anyChar dmEnd))
481− <|> (B.math <$> try (mStart *> manyTill (satisfy (/='\n')) mEnd))
478+math = (B.displayMath . trim <$> try (char ':' >> charsInTags "math"))
479+ <|> (B.math . trim <$> charsInTags "math")
480+ <|> (B.displayMath . trim <$> try (dmStart *> manyTill anyChar dmEnd))
481+ <|> (B.math . trim <$> try (mStart *> manyTill (satisfy (/='\n')) mEnd))
482482 where dmStart = string "\\["
483483 dmEnd = try (string "\\]")
484484 mStart = string "\\("
tests/mediawiki-reader.native+1
@@ -163,6 +163,7 @@ Pandoc (Meta {unMeta = fromList []})
163163 ,[Plain [Str "The",Space,Str "Hague"]]]
164164,Header 2 ("",[],[]) [Str "math"]
165165,Para [Str "Here",Space,Str "is",Space,Str "some",Space,Math InlineMath "x=\\frac{y^\\pi}{z}",Str "."]
166+,Para [Str "With",Space,Str "spaces:",Space,Math InlineMath "x=\\frac{y^\\pi}{z}",Str "."]
166167,Header 2 ("",[],[]) [Str "preformatted",Space,Str "blocks"]
167168,Para [Code ("",[],[]) "Start\160each\160line\160with\160a\160space.",LineBreak,Code ("",[],[]) "Text\160is\160",Strong [Code ("",[],[]) "preformatted"],Code ("",[],[]) "\160and",LineBreak,Emph [Code ("",[],[]) "markups"],Code ("",[],[]) "\160",Strong [Emph [Code ("",[],[]) "can"]],Code ("",[],[]) "\160be\160done."]
168169,Para [Code ("",[],[]) "\160hell\160\160\160\160\160\160yeah"]
tests/mediawiki-reader.wiki+2
@@ -248,6 +248,8 @@ ends the list.
248248
249249Here is some <math>x=\frac{y^\pi}{z}</math>.
250250
251+With spaces: <math> x=\frac{y^\pi}{z} </math>.
252+
251253== preformatted blocks ==
252254
253255 Start each line with a space.