parent
096cbe6987
commit
5945c3b011
3 changed files with 234 additions and 16 deletions
|
@ -115,21 +115,19 @@ parseTable = do
|
|||
isMTable _ = False
|
||||
MTable _opts aligns rows pos <- msatisfy isMTable
|
||||
case aligns of
|
||||
[as] -> do
|
||||
[as] -> try (do
|
||||
let as' = map (columnTypeToAlignment . columnType) as
|
||||
if all isJust as'
|
||||
then do
|
||||
let alignments = catMaybes as'
|
||||
let (headerRow', bodyRows') =
|
||||
case rows of
|
||||
(h:[x]:bs)
|
||||
| isHrule x -> (h, bs)
|
||||
_ -> ([], rows)
|
||||
headerRow <- mapM parseTableCell headerRow'
|
||||
bodyRows <- mapM (mapM parseTableCell) bodyRows'
|
||||
return $ B.table mempty (zip alignments (repeat 0.0))
|
||||
headerRow bodyRows
|
||||
else fallback pos
|
||||
guard $ all isJust as'
|
||||
let alignments = catMaybes as'
|
||||
let (headerRow', bodyRows') =
|
||||
case rows of
|
||||
(h:[x]:bs)
|
||||
| isHrule x -> (h, bs)
|
||||
_ -> ([], rows)
|
||||
headerRow <- mapM parseTableCell headerRow'
|
||||
bodyRows <- mapM (mapM parseTableCell) bodyRows'
|
||||
return $ B.table mempty (zip alignments (repeat 0.0))
|
||||
headerRow bodyRows) <|> fallback pos
|
||||
_ -> fallback pos
|
||||
|
||||
where
|
||||
|
@ -137,7 +135,10 @@ parseTable = do
|
|||
parseTableCell ts = do
|
||||
st <- getState
|
||||
let ts' = Foldable.toList $ unGroffTokens ts
|
||||
res <- lift $ readWithMTokens (mconcat <$> many parseBlock <* eof) st ts'
|
||||
let tcell = do
|
||||
skipMany memptyLine
|
||||
plain . trimInlines <$> (parseInlines <* eof)
|
||||
res <- lift $ readWithMTokens tcell st ts'
|
||||
case res of
|
||||
Left e -> throwError e
|
||||
Right x -> return x
|
||||
|
|
|
@ -221,3 +221,154 @@ and I.
|
|||
.auth "John Jones"
|
||||
.ds me The \f[B]Author\f[R]
|
||||
It's \*(me.
|
||||
.SH Tables
|
||||
.TS
|
||||
tab(@);
|
||||
r l c l.
|
||||
T{
|
||||
Right
|
||||
T}@T{
|
||||
Left
|
||||
T}@T{
|
||||
Center
|
||||
T}@T{
|
||||
Default
|
||||
T}
|
||||
_
|
||||
T{
|
||||
12
|
||||
T}@T{
|
||||
12
|
||||
T}@T{
|
||||
12
|
||||
T}@T{
|
||||
12
|
||||
T}
|
||||
T{
|
||||
123
|
||||
T}@T{
|
||||
123
|
||||
T}@T{
|
||||
123
|
||||
T}@T{
|
||||
123
|
||||
T}
|
||||
T{
|
||||
1
|
||||
T}@T{
|
||||
1
|
||||
T}@T{
|
||||
1
|
||||
T}@T{
|
||||
1
|
||||
T}
|
||||
.TE
|
||||
.TS
|
||||
allbox tab(;);
|
||||
rlcl.
|
||||
T{
|
||||
Right
|
||||
T};T{
|
||||
Left
|
||||
T};T{
|
||||
Center
|
||||
T};T{
|
||||
Left
|
||||
\f[I]more\f[R]
|
||||
T}
|
||||
_
|
||||
T{
|
||||
12
|
||||
T};T{
|
||||
12
|
||||
T};T{
|
||||
12
|
||||
T};T{
|
||||
12
|
||||
T}
|
||||
T{
|
||||
123
|
||||
T};T{
|
||||
123
|
||||
T};T{
|
||||
123
|
||||
T};T{
|
||||
123
|
||||
T}
|
||||
T{
|
||||
1
|
||||
T};T{
|
||||
1
|
||||
T};T{
|
||||
1
|
||||
T};T{
|
||||
1
|
||||
T}
|
||||
.TE
|
||||
.TS
|
||||
tab(@);
|
||||
cw(10.5n) lw(9.6n) rw(11.4n) lw(24.5n).
|
||||
T{
|
||||
Centered Header
|
||||
T}@T{
|
||||
Left Aligned
|
||||
T}@T{
|
||||
Right Aligned
|
||||
T}@T{
|
||||
Default aligned
|
||||
T}
|
||||
_
|
||||
T{
|
||||
First
|
||||
T}@T{
|
||||
row
|
||||
T}@T{
|
||||
12.0
|
||||
T}@T{
|
||||
Example of a row that spans multiple lines.
|
||||
T}
|
||||
T{
|
||||
Second
|
||||
T}@T{
|
||||
row
|
||||
T}@T{
|
||||
5.0
|
||||
T}@T{
|
||||
Here\[cq]s another one.
|
||||
Note the blank line between rows.
|
||||
T}
|
||||
.TE
|
||||
.PP
|
||||
Table without column headers:
|
||||
.PP
|
||||
.TS
|
||||
tab(@);
|
||||
r l c r.
|
||||
T{
|
||||
12
|
||||
T}@T{
|
||||
12
|
||||
T}@T{
|
||||
12
|
||||
T}@T{
|
||||
12
|
||||
T}
|
||||
T{
|
||||
123
|
||||
T}@T{
|
||||
123
|
||||
T}@T{
|
||||
123
|
||||
T}@T{
|
||||
123
|
||||
T}
|
||||
T{
|
||||
1
|
||||
T}@T{
|
||||
1
|
||||
T}@T{
|
||||
1
|
||||
T}@T{
|
||||
1
|
||||
T}
|
||||
.TE
|
||||
|
|
|
@ -103,4 +103,70 @@ Pandoc (Meta {unMeta = fromList [("date",MetaInlines [Str "Oct",Space,Str "17,",
|
|||
,Para [Link ("",[],[]) [Str "some",Space,Str "randomsite"] ("http://example.com",""),Str "."]
|
||||
,Para [Link ("",[],[]) [Str "my",Space,Str "email",Space,Str "address"] ("mailto:me@example.com",""),Str "."]
|
||||
,Header 1 ("",[],[]) [Str "Macros"]
|
||||
,Para [Strong [Str "Me",Space,Str "Myself"],Space,Str "and",Space,Str "I.",Space,Emph [Str "The",Space,Str "author",Space,Str "is",Space,Str "John",Space,Str "Jones."],Space,Str "It's",Space,Str "The",Space,Strong [Str "Author"],Str "."]]
|
||||
,Para [Strong [Str "Me",Space,Str "Myself"],Space,Str "and",Space,Str "I.",Space,Emph [Str "The",Space,Str "author",Space,Str "is",Space,Str "John",Space,Str "Jones."],Space,Str "It's",Space,Str "The",Space,Strong [Str "Author"],Str "."]
|
||||
,Header 1 ("",[],[]) [Str "Tables"]
|
||||
,Table [] [AlignRight,AlignLeft,AlignCenter,AlignLeft] [0.0,0.0,0.0,0.0]
|
||||
[[Plain [Str "Right"]]
|
||||
,[Plain [Str "Left"]]
|
||||
,[Plain [Str "Center"]]
|
||||
,[Plain [Str "Default"]]]
|
||||
[[[Plain [Str "12"]]
|
||||
,[Plain [Str "12"]]
|
||||
,[Plain [Str "12"]]
|
||||
,[Plain [Str "12"]]]
|
||||
,[[Plain [Str "123"]]
|
||||
,[Plain [Str "123"]]
|
||||
,[Plain [Str "123"]]
|
||||
,[Plain [Str "123"]]]
|
||||
,[[Plain [Str "1"]]
|
||||
,[Plain [Str "1"]]
|
||||
,[Plain [Str "1"]]
|
||||
,[Plain [Str "1"]]]]
|
||||
,Table [] [AlignRight,AlignLeft,AlignCenter,AlignLeft] [0.0,0.0,0.0,0.0]
|
||||
[[Plain [Str "Right"]]
|
||||
,[Plain [Str "Left"]]
|
||||
,[Plain [Str "Center"]]
|
||||
,[Plain [Str "Left",Space,Emph [Str "more"]]]]
|
||||
[[[Plain [Str "12"]]
|
||||
,[Plain [Str "12"]]
|
||||
,[Plain [Str "12"]]
|
||||
,[Plain [Str "12"]]]
|
||||
,[[Plain [Str "123"]]
|
||||
,[Plain [Str "123"]]
|
||||
,[Plain [Str "123"]]
|
||||
,[Plain [Str "123"]]]
|
||||
,[[Plain [Str "1"]]
|
||||
,[Plain [Str "1"]]
|
||||
,[Plain [Str "1"]]
|
||||
,[Plain [Str "1"]]]]
|
||||
,Table [] [AlignCenter,AlignLeft,AlignRight,AlignLeft] [0.0,0.0,0.0,0.0]
|
||||
[[Plain [Str "Centered",Space,Str "Header"]]
|
||||
,[Plain [Str "Left",Space,Str "Aligned"]]
|
||||
,[Plain [Str "Right",Space,Str "Aligned"]]
|
||||
,[Plain [Str "Default",Space,Str "aligned"]]]
|
||||
[[[Plain [Str "First"]]
|
||||
,[Plain [Str "row"]]
|
||||
,[Plain [Str "12.0"]]
|
||||
,[Plain [Str "Example",Space,Str "of",Space,Str "a",Space,Str "row",Space,Str "that",Space,Str "spans",Space,Str "multiple",Space,Str "lines."]]]
|
||||
,[[Plain [Str "Second"]]
|
||||
,[Plain [Str "row"]]
|
||||
,[Plain [Str "5.0"]]
|
||||
,[Plain [Str "Here\8217s",Space,Str "another",Space,Str "one.",Space,Str "Note",Space,Str "the",Space,Str "blank",Space,Str "line",Space,Str "between",Space,Str "rows."]]]]
|
||||
,Para [Str "Table",Space,Str "without",Space,Str "column",Space,Str "headers:"]
|
||||
,Table [] [AlignRight,AlignLeft,AlignCenter,AlignRight] [0.0,0.0,0.0,0.0]
|
||||
[[]
|
||||
,[]
|
||||
,[]
|
||||
,[]]
|
||||
[[[Plain [Str "12"]]
|
||||
,[Plain [Str "12"]]
|
||||
,[Plain [Str "12"]]
|
||||
,[Plain [Str "12"]]]
|
||||
,[[Plain [Str "123"]]
|
||||
,[Plain [Str "123"]]
|
||||
,[Plain [Str "123"]]
|
||||
,[Plain [Str "123"]]]
|
||||
,[[Plain [Str "1"]]
|
||||
,[Plain [Str "1"]]
|
||||
,[Plain [Str "1"]]
|
||||
,[Plain [Str "1"]]]]]
|
||||
|
|
Loading…
Add table
Reference in a new issue