git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1999 from synsem/latex-reader-tables
c7c4591John MacFarlane
src/Text/Pandoc/Readers/LaTeX.hs+2−2
@@ -1275,7 +1275,7 @@ complexNatbibCitation mode = try $ do
1275parseAligns :: LP [Alignment]
1275parseAligns :: LP [Alignment]
1276parseAligns = try $ do
1276parseAligns = try $ do
1277 char '{'
1277 char '{'
1278− let maybeBar = skipMany $ sp <|> () <$ char '|' <|> () <$ try (string "@{}")
1278+ let maybeBar = skipMany $ sp <|> () <$ char '|' <|> () <$ (char '@' >> braced)
1279 maybeBar
1279 maybeBar
1280 let cAlign = AlignCenter <$ char 'c'
1280 let cAlign = AlignCenter <$ char 'c'
1281 let lAlign = AlignLeft <$ char 'l'
1281 let lAlign = AlignLeft <$ char 'l'
@@ -1314,7 +1314,7 @@ parseTableRow cols = try $ do
1314simpTable :: Bool -> LP Blocks
1314simpTable :: Bool -> LP Blocks
1315simpTable hasWidthParameter = try $ do
1315simpTable hasWidthParameter = try $ do
1316 when hasWidthParameter $ () <$ (spaces >> tok)
1316 when hasWidthParameter $ () <$ (spaces >> tok)
1317− spaces
1317+ skipopts
1318 aligns <- parseAligns
1318 aligns <- parseAligns
1319 let cols = length aligns
1319 let cols = length aligns
1320 optional hline
1320 optional hline
tests/Tests/Readers/LaTeX.hs+39
@@ -7,6 +7,7 @@ import Tests.Helpers
7import Tests.Arbitrary()
7import Tests.Arbitrary()
8import Text.Pandoc.Builder
8import Text.Pandoc.Builder
9import Text.Pandoc
9import Text.Pandoc
10+import Data.Monoid (mempty)
10
11
11latex :: String -> Pandoc
12latex :: String -> Pandoc
12latex = readLaTeX def
13latex = readLaTeX def
@@ -16,6 +17,10 @@ infix 4 =:
16 => String -> (String, c) -> Test
17 => String -> (String, c) -> Test
17(=:) = test latex
18(=:) = test latex
18
19
20+simpleTable' :: [Alignment] -> [[Blocks]] -> Blocks
21+simpleTable' aligns = table "" (zip aligns (repeat 0.0))
22+ (map (const mempty) aligns)
23+
19tests :: [Test]
24tests :: [Test]
20tests = [ testGroup "basic"
25tests = [ testGroup "basic"
21 [ "simple" =:
26 [ "simple" =:
@@ -62,6 +67,40 @@ tests = [ testGroup "basic"
62 "\\begin{lstlisting}\\end{lstlisting}" =?> codeBlock ""
67 "\\begin{lstlisting}\\end{lstlisting}" =?> codeBlock ""
63 ]
68 ]
64
69
70+ , testGroup "tables"
71+ [ "Single cell table" =:
72+ "\\begin{tabular}{|l|}Test\\\\\\end{tabular}" =?>
73+ simpleTable' [AlignLeft] [[plain "Test"]]
74+ , "Multi cell table" =:
75+ "\\begin{tabular}{|rl|}One & Two\\\\ \\end{tabular}" =?>
76+ simpleTable' [AlignRight,AlignLeft] [[plain "One", plain "Two"]]
77+ , "Multi line table" =:
78+ unlines [ "\\begin{tabular}{|c|}"
79+ , "One\\\\"
80+ , "Two\\\\"
81+ , "Three\\\\"
82+ , "\\end{tabular}" ] =?>
83+ simpleTable' [AlignCenter]
84+ [[plain "One"], [plain "Two"], [plain "Three"]]
85+ , "Empty table" =:
86+ "\\begin{tabular}{}\\end{tabular}" =?>
87+ simpleTable' [] []
88+ , "Table with fixed column width" =:
89+ "\\begin{tabular}{|p{5cm}r|}One & Two\\\\ \\end{tabular}" =?>
90+ simpleTable' [AlignLeft,AlignRight] [[plain "One", plain "Two"]]
91+ , "Table with empty column separators" =:
92+ "\\begin{tabular}{@{}r@{}l}One & Two\\\\ \\end{tabular}" =?>
93+ simpleTable' [AlignRight,AlignLeft] [[plain "One", plain "Two"]]
94+ , "Table with custom column separators" =:
95+ unlines [ "\\begin{tabular}{@{($\\to$)}r@{\\hspace{2cm}}l}"
96+ , "One&Two\\\\"
97+ , "\\end{tabular}" ] =?>
98+ simpleTable' [AlignRight,AlignLeft] [[plain "One", plain "Two"]]
99+ , "Table with vertical alignment argument" =:
100+ "\\begin{tabular}[t]{r|r}One & Two\\\\ \\end{tabular}" =?>
101+ simpleTable' [AlignRight,AlignRight] [[plain "One", plain "Two"]]
102+ ]
103+
65 , testGroup "citations"
104 , testGroup "citations"
66 [ natbibCitations
105 [ natbibCitations
67 , biblatexCitations
106 , biblatexCitations