MediaWiki reader: Trim contents of <math> tags.

Otherwise we get problems when converting to markdown.

Closes #1027.
This commit is contained in:
John MacFarlane 2013-10-18 17:50:43 -07:00
parent 1f29f4678e
commit e5feed00f7
3 changed files with 8 additions and 5 deletions

View file

@ -43,7 +43,7 @@ import Text.Pandoc.Readers.HTML ( htmlTag, isBlockTag, isCommentTag )
import Text.Pandoc.XML ( fromEntities )
import Text.Pandoc.Parsing hiding ( nested )
import Text.Pandoc.Walk ( walk )
import Text.Pandoc.Shared ( stripTrailingNewlines, safeRead, stringify )
import Text.Pandoc.Shared ( stripTrailingNewlines, safeRead, stringify, trim )
import Data.Monoid (mconcat, mempty)
import Control.Applicative ((<$>), (<*), (*>), (<$))
import Control.Monad
@ -475,10 +475,10 @@ str :: MWParser Inlines
str = B.str <$> many1 (noneOf $ specialChars ++ spaceChars)
math :: MWParser Inlines
math = (B.displayMath <$> try (char ':' >> charsInTags "math"))
<|> (B.math <$> charsInTags "math")
<|> (B.displayMath <$> try (dmStart *> manyTill anyChar dmEnd))
<|> (B.math <$> try (mStart *> manyTill (satisfy (/='\n')) mEnd))
math = (B.displayMath . trim <$> try (char ':' >> charsInTags "math"))
<|> (B.math . trim <$> charsInTags "math")
<|> (B.displayMath . trim <$> try (dmStart *> manyTill anyChar dmEnd))
<|> (B.math . trim <$> try (mStart *> manyTill (satisfy (/='\n')) mEnd))
where dmStart = string "\\["
dmEnd = try (string "\\]")
mStart = string "\\("

View file

@ -163,6 +163,7 @@ Pandoc (Meta {unMeta = fromList []})
,[Plain [Str "The",Space,Str "Hague"]]]
,Header 2 ("",[],[]) [Str "math"]
,Para [Str "Here",Space,Str "is",Space,Str "some",Space,Math InlineMath "x=\\frac{y^\\pi}{z}",Str "."]
,Para [Str "With",Space,Str "spaces:",Space,Math InlineMath "x=\\frac{y^\\pi}{z}",Str "."]
,Header 2 ("",[],[]) [Str "preformatted",Space,Str "blocks"]
,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."]
,Para [Code ("",[],[]) "\160hell\160\160\160\160\160\160yeah"]

View file

@ -248,6 +248,8 @@ ends the list.
Here is some <math>x=\frac{y^\pi}{z}</math>.
With spaces: <math> x=\frac{y^\pi}{z} </math>.
== preformatted blocks ==
Start each line with a space.