From 8c3b5dd3ae10dade9f8a52fcba456f1cd8d085c9 Mon Sep 17 00:00:00 2001 From: "Laurent P. René de Cotret" Date: Thu, 23 Jul 2020 14:23:21 -0400 Subject: Col-span and row-span in LaTeX reader (#6470) Add multirow and multicolumn support in LaTex reader. Partially addresses #6311. --- test/Tests/Readers/LaTeX.hs | 58 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/Tests/Readers/LaTeX.hs b/test/Tests/Readers/LaTeX.hs index 821747f26..74906fab4 100644 --- a/test/Tests/Readers/LaTeX.hs +++ b/test/Tests/Readers/LaTeX.hs @@ -35,13 +35,17 @@ infix 4 =: => String -> (Text, c) -> TestTree (=:) = test latex -simpleTable' :: [Alignment] -> [[Blocks]] -> Blocks -simpleTable' aligns rows +table' :: [Alignment] -> [Row] -> Blocks +table' aligns rows = table emptyCaption (zip aligns (repeat ColWidthDefault)) (TableHead nullAttr []) - [TableBody nullAttr 0 [] $ map toRow rows] + [TableBody nullAttr 0 [] rows] (TableFoot nullAttr []) + +simpleTable' :: [Alignment] -> [[Blocks]] -> Blocks +simpleTable' aligns rows + = table' aligns (map toRow rows) where toRow = Row nullAttr . map simpleCell @@ -137,6 +141,54 @@ tests = [ testGroup "tokenization" , "Table with vertical alignment argument" =: "\\begin{tabular}[t]{r|r}One & Two\\\\ \\end{tabular}" =?> simpleTable' [AlignRight,AlignRight] [[plain "One", plain "Two"]] + , "Table with multicolumn item" =: + "\\begin{tabular}{l c r}\\multicolumn{2}{c}{One} & Two\\\\ \\end{tabular}" =?> + table' [AlignLeft, AlignCenter, AlignRight] + [ Row nullAttr [ cell AlignCenter (RowSpan 1) (ColSpan 2) (plain "One") + , simpleCell (plain "Two") + ] + ] + , "Table with multirow item" =: + T.unlines ["\\begin{tabular}{c}" + ,"\\multirow{2}{c}{One}\\\\Two\\\\" + ,"\\end{tabular}" + ] =?> + table' [AlignCenter] + [ Row nullAttr [ cell AlignCenter (RowSpan 2) (ColSpan 1) (plain "One") ] + , Row nullAttr [ simpleCell (plain "Two") ] + ] + , "Table with nested multirow/multicolumn item" =: + T.unlines [ "\\begin{tabular}{c c c}" + , "\\multirow{2}{c}{\\multicolumn{2}{c}{One}}&Two\\\\" + , "Three\\\\" + , "Four&Five&Six\\\\" + , "\\end{tabular}" + ] =?> + table' [AlignCenter, AlignCenter, AlignCenter] + [ Row nullAttr [ cell AlignCenter (RowSpan 2) (ColSpan 2) (plain "One") + , simpleCell (plain "Two") + ] + , Row nullAttr [ simpleCell (plain "Three") ] + , Row nullAttr [ simpleCell (plain "Four") + , simpleCell (plain "Five") + , simpleCell (plain "Six") + ] + ] + , "Table with multicolumn header" =: + T.unlines [ "\\begin{tabular}{ |l|l| }" + , "\\hline\\multicolumn{2}{|c|}{Header}\\\\" + , "\\hline key & val\\\\" + , "\\hline\\end{tabular}" + ] =?> + table emptyCaption + (zip [AlignLeft, AlignLeft] (repeat ColWidthDefault)) + (TableHead nullAttr [ Row nullAttr [cell AlignCenter (RowSpan 1) (ColSpan 2) (plain "Header")]]) + [TableBody nullAttr 0 [] [Row nullAttr [ simpleCell (plain "key") + , simpleCell (plain "val") + ] + ] + ] + (TableFoot nullAttr []) ] , testGroup "citations" -- cgit v1.2.3