MediaWiki reader: Parse styles after '{|' table start.
This commit is contained in:
parent
aa476b42cb
commit
9a54a949c7
3 changed files with 39 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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"]]]]]
|
||||
|
|
|
@ -322,5 +322,11 @@ and cheese
|
|||
|
||||
|}
|
||||
|
||||
|
||||
{|
|
||||
| Orange || Apple || more
|
||||
|-
|
||||
| Bread || Pie || more
|
||||
|-
|
||||
| Butter || Ice cream || and more
|
||||
|}
|
||||
|
||||
|
|
Loading…
Reference in a new issue