@@ -30,7 +30,6 @@ Conversion of mediawiki text to 'Pandoc' document.
33−_ support images http://www.mediawiki.org/wiki/Help:Images
34_ support tables http://www.mediawiki.org/wiki/Help:Tables
33_ support tables http://www.mediawiki.org/wiki/Help:Tables
35- footnotes?
34- footnotes?
@@ -147,6 +146,7 @@ parseMediaWiki = do
148block :: MWParser Blocks
147block :: MWParser Blocks
149block = mempty <$ skipMany1 blankline
148block = mempty <$ skipMany1 blankline
150 <|> header
150 <|> header
151 <|> hrule
151 <|> hrule
152 <|> orderedList
152 <|> orderedList
@@ -161,6 +161,48 @@ block = mempty <$ skipMany1 blankline
161para :: MWParser Blocks
161para :: MWParser Blocks
162para = B.para . trimInlines . mconcat <$> many1 inline
162para = B.para . trimInlines . mconcat <$> many1 inline
164+table :: MWParser Blocks
167+ caption <- option mempty tableCaption
169+ hasheader <- option False $ True <$ (lookAhead (char '!'))
171+ rows' <- many $ try $ rowsep *> tableRow
173+ -- TODO handle cellspecs from styles and aligns...
174+ let cols = length $ head rows'
175+ let (headers,rows) = if hasheader
177+ else (replicate cols mempty, hdr:rows')
178+ let cellspecs = replicate cols (AlignDefault, 0.0)
179+ return $ B.table caption cellspecs headers rows
181+tableStart :: MWParser ()
182+tableStart = try $ guardColumnOne *> sym "{|" <* blanklines
184+tableEnd :: MWParser ()
185+tableEnd = try $ guardColumnOne *> sym "|}" <* blanklines
187+rowsep :: MWParser ()
188+rowsep = try $ guardColumnOne *> sym "|-" <* blanklines
190+-- TODO add something like 'guard inTable' since this is used in endline
191+cellsep :: MWParser ()
192+cellsep = try $ guardColumnOne <*
193+ (char '!' <|> (char '|' <* notFollowedBy (oneOf "-}+")))
195+tableCaption :: MWParser Inlines
196+tableCaption = try $ guardColumnOne *> sym "|+" *> skipMany spaceChar *>
197+ (trimInlines . mconcat <$> (many inline)) <* skipMany blankline
199+tableRow :: MWParser [Blocks]
200+tableRow = try $ many tableCell <* skipMany blankline
202+tableCell :: MWParser Blocks
204+ try $ cellsep *> skipMany spaceChar *> (mconcat <$> (many block))
164template :: MWParser Blocks
206template :: MWParser Blocks
165template = B.rawBlock "mediawiki" <$> doublebrackets
207template = B.rawBlock "mediawiki" <$> doublebrackets
166 where doublebrackets = try $ do
208 where doublebrackets = try $ do
@@ -200,9 +242,12 @@ syntaxhighlight attrs = try $ do
200hrule :: MWParser Blocks
242hrule :: MWParser Blocks
201hrule = B.horizontalRule <$ try (string "----" *> many (char '-') *> newline)
243hrule = B.horizontalRule <$ try (string "----" *> many (char '-') *> newline)
245+guardColumnOne :: MWParser ()
246+guardColumnOne = getPosition >>= \pos -> guard (sourceColumn pos == 1)
203preformatted :: MWParser Blocks
248preformatted :: MWParser Blocks
204preformatted = try $ do
249preformatted = try $ do
205− getPosition >>= \pos -> guard (sourceColumn pos == 1)
250+ guardColumnOne
207 let endline' = B.linebreak <$ (try $ newline <* char ' ')
252 let endline' = B.linebreak <$ (try $ newline <* char ' ')
208 let whitespace' = B.str <$> many1 ('\160' <$ spaceChar)
253 let whitespace' = B.str <$> many1 ('\160' <$ spaceChar)
@@ -219,8 +264,7 @@ preformatted = try $ do
220header :: MWParser Blocks
265header :: MWParser Blocks
221header = try $ do
266header = try $ do
222− col <- sourceColumn <$> getPosition
267+ guardColumnOne
223− guard $ col == 1 -- header must be at beginning of line
224 eqs <- many1 (char '=')
268 eqs <- many1 (char '=')
225 let lev = length eqs
269 let lev = length eqs
226 guard $ lev <= 6
270 guard $ lev <= 6
@@ -361,7 +405,7 @@ inlineTag = do
362special :: MWParser Inlines
406special :: MWParser Inlines
363special = B.str <$> count 1 (notFollowedBy' (htmlTag isBlockTag') *>
407special = B.str <$> count 1 (notFollowedBy' (htmlTag isBlockTag') *>
364− oneOf specialChars)
408+ notFollowedBy (char '|') *> oneOf specialChars)
366inlineHtml :: MWParser Inlines
410inlineHtml :: MWParser Inlines
367inlineHtml = B.rawInline "html" . snd <$> htmlTag isInlineTag
411inlineHtml = B.rawInline "html" . snd <$> htmlTag isInlineTag
@@ -373,6 +417,9 @@ endline :: MWParser ()
373endline = () <$ try (newline <*
417endline = () <$ try (newline <*
374 notFollowedBy blankline <*
418 notFollowedBy blankline <*
375 notFollowedBy' hrule <*
419 notFollowedBy' hrule <*
420+ notFollowedBy tableStart <*
421+ notFollowedBy' template <*
422+ notFollowedBy cellsep <*
376 notFollowedBy anyListStart)
423 notFollowedBy anyListStart)
378image :: MWParser Inlines
425image :: MWParser Inlines