MediaWiki reader: Parse styles after '{|' table start.

This commit is contained in:
John MacFarlane 2012-09-15 00:23:24 -04:00
parent aa476b42cb
commit 9a54a949c7
3 changed files with 39 additions and 3 deletions

View file

@ -164,6 +164,9 @@ para = B.para . trimInlines . mconcat <$> many1 inline
table :: MWParser Blocks
table = do
tableStart
styles <- manyTill anyChar newline
let tableWidth = maybe (1.0 :: Double) read
$ lookup "width" $ parseAttrs styles
caption <- option mempty tableCaption
optional rowsep
hasheader <- option False $ True <$ (lookAhead (char '!'))
@ -178,8 +181,22 @@ table = do
let cellspecs = replicate cols (AlignDefault, 0.0)
return $ B.table caption cellspecs headers rows
parseAttrs :: String -> [(String,String)]
parseAttrs s = case parse (many parseAttr) "attributes" s of
Right r -> r
Left _ -> []
parseAttr :: Parser String () (String, String)
parseAttr = try $ do
skipMany spaceChar
k <- many1 letter
char '='
char '"'
v <- many1Till anyChar (char '"')
return (k,v)
tableStart :: MWParser ()
tableStart = try $ guardColumnOne *> sym "{|" <* blanklines
tableStart = try $ guardColumnOne *> sym "{|"
tableEnd :: MWParser ()
tableEnd = try $ guardColumnOne *> sym "|}" <* blanklines

View file

@ -199,4 +199,17 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []})
,[Para [Str "Pie"]
,OrderedList (1,DefaultStyle,DefaultDelim)
[[Plain [Str "apple"]]
,[Plain [Str "carrot"]]]]]]]
,[Plain [Str "carrot"]]]]]]
,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0]
[[]
,[]
,[]]
[[[Para [Str "Orange"]]
,[Para [Str "Apple"]]
,[Para [Str "more"]]]
,[[Para [Str "Bread"]]
,[Para [Str "Pie"]]
,[Para [Str "more"]]]
,[[Para [Str "Butter"]]
,[Para [Str "Ice",Space,Str "cream"]]
,[Para [Str "and",Space,Str "more"]]]]]

View file

@ -322,5 +322,11 @@ and cheese
|}
{|
| Orange || Apple || more
|-
| Bread || Pie || more
|-
| Butter || Ice cream || and more
|}