git.iko.soy/typeable/pandoc
on master help sign in
Merge branch 'master' of github.com:jgm/pandoc into tests
09e9a86John MacFarlane
src/Text/Pandoc/Parsing.hs+5−5
@@ -488,8 +488,8 @@ gridTableWith block tableCaption headless =
488 tableWith (gridTableHeader headless block) (gridTableRow block) (gridTableSep '-') gridTableFooter tableCaption
488 tableWith (gridTableHeader headless block) (gridTableRow block) (gridTableSep '-') gridTableFooter tableCaption
489
489
490gridTableSplitLine :: [Int] -> String -> [String]
490gridTableSplitLine :: [Int] -> String -> [String]
491−gridTableSplitLine indices line =
491+gridTableSplitLine indices line = map removeFinalBar $ tail $
492− map removeFinalBar $ tail $ splitByIndices (init indices) line
492+ splitByIndices (init indices) $ removeTrailingSpace line
493
493
494gridPart :: Char -> GenParser Char st (Int, Int)
494gridPart :: Char -> GenParser Char st (Int, Int)
495gridPart ch = do
495gridPart ch = do
@@ -501,8 +501,8 @@ gridDashedLines :: Char -> GenParser Char st [(Int,Int)]
501gridDashedLines ch = try $ char '+' >> many1 (gridPart ch) >>~ blankline
501gridDashedLines ch = try $ char '+' >> many1 (gridPart ch) >>~ blankline
502
502
503removeFinalBar :: String -> String
503removeFinalBar :: String -> String
504−removeFinalBar = reverse . dropWhile (=='|') . dropWhile (`elem` " \t") .
504+removeFinalBar =
505− reverse
505+ reverse . dropWhile (`elem` " \t") . dropWhile (=='|') . reverse
506
506
507-- | Separator between rows of grid table.
507-- | Separator between rows of grid table.
508gridTableSep :: Char -> GenParser Char ParserState Char
508gridTableSep :: Char -> GenParser Char ParserState Char
@@ -539,7 +539,7 @@ gridTableRawLine :: [Int] -> GenParser Char ParserState [String]
539gridTableRawLine indices = do
539gridTableRawLine indices = do
540 char '|'
540 char '|'
541 line <- many1Till anyChar newline
541 line <- many1Till anyChar newline
542− return (gridTableSplitLine indices $ removeTrailingSpace line)
542+ return (gridTableSplitLine indices line)
543
543
544-- | Parse row of grid table.
544-- | Parse row of grid table.
545gridTableRow :: GenParser Char ParserState Block
545gridTableRow :: GenParser Char ParserState Block
src/Text/Pandoc/Writers/LaTeX.hs+12−9
@@ -34,7 +34,7 @@ import Text.Pandoc.Generic
34import Text.Pandoc.Shared
34import Text.Pandoc.Shared
35import Text.Pandoc.Templates
35import Text.Pandoc.Templates
36import Text.Printf ( printf )
36import Text.Printf ( printf )
37−import Data.List ( (\\), isSuffixOf, isPrefixOf, intercalate )
37+import Data.List ( (\\), isSuffixOf, isPrefixOf, intercalate, intersperse )
38import Data.Char ( toLower, isPunctuation )
38import Data.Char ( toLower, isPunctuation )
39import Control.Monad.State
39import Control.Monad.State
40import Text.Pandoc.Pretty
40import Text.Pandoc.Pretty
@@ -241,9 +241,9 @@ blockToLaTeX (Header level lst) = do
241blockToLaTeX (Table caption aligns widths heads rows) = do
241blockToLaTeX (Table caption aligns widths heads rows) = do
242 headers <- if all null heads
242 headers <- if all null heads
243 then return empty
243 then return empty
244− else liftM ($$ "\\hline") $ tableRowToLaTeX heads
244+ else liftM ($$ "\\hline") $ (tableRowToLaTeX widths) heads
245 captionText <- inlineListToLaTeX caption
245 captionText <- inlineListToLaTeX caption
246− rows' <- mapM tableRowToLaTeX rows
246+ rows' <- mapM (tableRowToLaTeX widths) rows
247 let colDescriptors = concat $ zipWith toColDescriptor widths aligns
247 let colDescriptors = concat $ zipWith toColDescriptor widths aligns
248 let tableBody = text ("\\begin{tabular}{" ++ colDescriptors ++ "}") $$
248 let tableBody = text ("\\begin{tabular}{" ++ colDescriptors ++ "}") $$
249 headers $$ vcat rows' $$ "\\end{tabular}"
249 headers $$ vcat rows' $$ "\\end{tabular}"
@@ -267,16 +267,19 @@ toColDescriptor width align = ">{\\PBS" ++
267 AlignRight -> "\\raggedleft"
267 AlignRight -> "\\raggedleft"
268 AlignCenter -> "\\centering"
268 AlignCenter -> "\\centering"
269 AlignDefault -> "\\raggedright") ++
269 AlignDefault -> "\\raggedright") ++
270− "\\hspace{0pt}}p{" ++ printf "%.2f" width ++
270+ "\\hspace{0pt}}p{" ++ printf "%.2f" width ++ "\\columnwidth}"
271− "\\columnwidth}"
272
271
273blockListToLaTeX :: [Block] -> State WriterState Doc
272blockListToLaTeX :: [Block] -> State WriterState Doc
274blockListToLaTeX lst = mapM blockToLaTeX lst >>= return . vcat
273blockListToLaTeX lst = mapM blockToLaTeX lst >>= return . vcat
275
274
276−tableRowToLaTeX :: [[Block]] -> State WriterState Doc
275+tableRowToLaTeX :: [Double] -> [[Block]] -> State WriterState Doc
276+tableRowToLaTeX widths cols = do
277−tableRowToLaTeX cols = mapM blockListToLaTeX cols >>=
277+ renderedCells <- mapM blockListToLaTeX cols
278− return . ($$ text "\\\\") . foldl (\row item -> row $$
278+ let toCell 0 c = c
279− (if isEmpty row then text "" else text " & ") <> item) empty
279+ toCell w c = "\\parbox{" <> text (printf "%.2f" w) <>
280+ "\\columnwidth}{" <> c <> cr <> "}"
281+ let cells = zipWith toCell widths renderedCells
282+ return $ (hcat $ intersperse (" & ") cells) <> "\\\\"
280
283
281listItemToLaTeX :: [Block] -> State WriterState Doc
284listItemToLaTeX :: [Block] -> State WriterState Doc
282listItemToLaTeX lst = blockListToLaTeX lst >>= return . (text "\\item" $$) .
285listItemToLaTeX lst = blockListToLaTeX lst >>= return . (text "\\item" $$) .
tests/tables.latex+58−115
@@ -3,27 +3,11 @@ Simple table with caption:
3\begin{table}[h]
3\begin{table}[h]
4\begin{center}
4\begin{center}
5\begin{tabular}{rlcl}
5\begin{tabular}{rlcl}
6−Right
7− & Left
8− & Center
9− & Default
6+Right & Left & Center & Default\\
10−\\
11\hline
7\hline
12−12
8+12 & 12 & 12 & 12\\
13− & 12
14− & 12
15− & 12
16−\\
17−123
9+123 & 123 & 123 & 123\\
18− & 123
19− & 123
20− & 123
21−\\
22−1
10+1 & 1 & 1 & 1\\
23− & 1
24− & 1
25− & 1
26−\\
27\end{tabular}
11\end{tabular}
28\end{center}
12\end{center}
29\caption{Demonstration of simple table syntax.}
13\caption{Demonstration of simple table syntax.}
@@ -33,27 +17,11 @@ Simple table without caption:
33
17
34\begin{center}
18\begin{center}
35\begin{tabular}{rlcl}
19\begin{tabular}{rlcl}
36−Right
37− & Left
38− & Center
39− & Default
20+Right & Left & Center & Default\\
40−\\
41\hline
21\hline
42−12
22+12 & 12 & 12 & 12\\
43− & 12
44− & 12
45− & 12
46−\\
47−123
23+123 & 123 & 123 & 123\\
48− & 123
49− & 123
50− & 123
51−\\
52−1
24+1 & 1 & 1 & 1\\
53− & 1
54− & 1
55− & 1
56−\\
57\end{tabular}
25\end{tabular}
58\end{center}
26\end{center}
59
27
@@ -62,27 +30,11 @@ Simple table indented two spaces:
62\begin{table}[h]
30\begin{table}[h]
63\begin{center}
31\begin{center}
64\begin{tabular}{rlcl}
32\begin{tabular}{rlcl}
65−Right
66− & Left
67− & Center
68− & Default
33+Right & Left & Center & Default\\
69−\\
70\hline
34\hline
71−12
35+12 & 12 & 12 & 12\\
72− & 12
73− & 12
74− & 12
75−\\
76−123
36+123 & 123 & 123 & 123\\
77− & 123
78− & 123
79− & 123
80−\\
81−1
37+1 & 1 & 1 & 1\\
82− & 1
83− & 1
84− & 1
85−\\
86\end{tabular}
38\end{tabular}
87\end{center}
39\end{center}
88\caption{Demonstration of simple table syntax.}
40\caption{Demonstration of simple table syntax.}
@@ -93,22 +45,23 @@ Multiline table with caption:
93\begin{table}[h]
45\begin{table}[h]
94\begin{center}
46\begin{center}
95\begin{tabular}{>{\PBS\centering\hspace{0pt}}p{0.15\columnwidth}>{\PBS\raggedright\hspace{0pt}}p{0.14\columnwidth}>{\PBS\raggedleft\hspace{0pt}}p{0.16\columnwidth}>{\PBS\raggedright\hspace{0pt}}p{0.34\columnwidth}}
47\begin{tabular}{>{\PBS\centering\hspace{0pt}}p{0.15\columnwidth}>{\PBS\raggedright\hspace{0pt}}p{0.14\columnwidth}>{\PBS\raggedleft\hspace{0pt}}p{0.16\columnwidth}>{\PBS\raggedright\hspace{0pt}}p{0.34\columnwidth}}
96−Centered Header
48+\parbox{0.15\columnwidth}{Centered Header
97− & Left Aligned
49+} & \parbox{0.14\columnwidth}{Left Aligned
98− & Right Aligned
50+} & \parbox{0.16\columnwidth}{Right Aligned
99− & Default aligned
51+} & \parbox{0.34\columnwidth}{Default aligned
100−\\
52+}\\
101\hline
53\hline
102−First
54+\parbox{0.15\columnwidth}{First
103− & row
55+} & \parbox{0.14\columnwidth}{row
104− & 12.0
56+} & \parbox{0.16\columnwidth}{12.0
105− & Example of a row that spans multiple lines.
57+} & \parbox{0.34\columnwidth}{Example of a row that spans multiple lines.
106−\\
58+}\\
107−Second
59+\parbox{0.15\columnwidth}{Second
108− & row
60+} & \parbox{0.14\columnwidth}{row
109− & 5.0
61+} & \parbox{0.16\columnwidth}{5.0
110− & Here's another one. Note the blank line between rows.
62+} & \parbox{0.34\columnwidth}{Here's another one. Note the blank line between
63+rows.
111−\\
64+}\\
112\end{tabular}
65\end{tabular}
113\end{center}
66\end{center}
114\caption{Here's the caption. It may span multiple lines.}
67\caption{Here's the caption. It may span multiple lines.}
@@ -118,22 +71,23 @@ Multiline table without caption:
118
71
119\begin{center}
72\begin{center}
120\begin{tabular}{>{\PBS\centering\hspace{0pt}}p{0.15\columnwidth}>{\PBS\raggedright\hspace{0pt}}p{0.14\columnwidth}>{\PBS\raggedleft\hspace{0pt}}p{0.16\columnwidth}>{\PBS\raggedright\hspace{0pt}}p{0.34\columnwidth}}
73\begin{tabular}{>{\PBS\centering\hspace{0pt}}p{0.15\columnwidth}>{\PBS\raggedright\hspace{0pt}}p{0.14\columnwidth}>{\PBS\raggedleft\hspace{0pt}}p{0.16\columnwidth}>{\PBS\raggedright\hspace{0pt}}p{0.34\columnwidth}}
121−Centered Header
74+\parbox{0.15\columnwidth}{Centered Header
122− & Left Aligned
75+} & \parbox{0.14\columnwidth}{Left Aligned
123− & Right Aligned
76+} & \parbox{0.16\columnwidth}{Right Aligned
124− & Default aligned
77+} & \parbox{0.34\columnwidth}{Default aligned
125−\\
78+}\\
126\hline
79\hline
127−First
80+\parbox{0.15\columnwidth}{First
128− & row
81+} & \parbox{0.14\columnwidth}{row
129− & 12.0
82+} & \parbox{0.16\columnwidth}{12.0
130− & Example of a row that spans multiple lines.
83+} & \parbox{0.34\columnwidth}{Example of a row that spans multiple lines.
131−\\
84+}\\
132−Second
85+\parbox{0.15\columnwidth}{Second
133− & row
86+} & \parbox{0.14\columnwidth}{row
134− & 5.0
87+} & \parbox{0.16\columnwidth}{5.0
135− & Here's another one. Note the blank line between rows.
88+} & \parbox{0.34\columnwidth}{Here's another one. Note the blank line between
89+rows.
136−\\
90+}\\
137\end{tabular}
91\end{tabular}
138\end{center}
92\end{center}
139
93
@@ -141,21 +95,9 @@ Table without column headers:
141
95
142\begin{center}
96\begin{center}
143\begin{tabular}{rlcr}
97\begin{tabular}{rlcr}
144−12
98+12 & 12 & 12 & 12\\
145− & 12
146− & 12
147− & 12
148−\\
149−123
99+123 & 123 & 123 & 123\\
150− & 123
151− & 123
152− & 123
153−\\
154−1
100+1 & 1 & 1 & 1\\
155− & 1
156− & 1
157− & 1
158−\\
159\end{tabular}
101\end{tabular}
160\end{center}
102\end{center}
161
103
@@ -163,16 +105,17 @@ Multiline table without column headers:
163
105
164\begin{center}
106\begin{center}
165\begin{tabular}{>{\PBS\centering\hspace{0pt}}p{0.15\columnwidth}>{\PBS\raggedright\hspace{0pt}}p{0.14\columnwidth}>{\PBS\raggedleft\hspace{0pt}}p{0.16\columnwidth}>{\PBS\raggedright\hspace{0pt}}p{0.34\columnwidth}}
107\begin{tabular}{>{\PBS\centering\hspace{0pt}}p{0.15\columnwidth}>{\PBS\raggedright\hspace{0pt}}p{0.14\columnwidth}>{\PBS\raggedleft\hspace{0pt}}p{0.16\columnwidth}>{\PBS\raggedright\hspace{0pt}}p{0.34\columnwidth}}
166−First
108+\parbox{0.15\columnwidth}{First
167− & row
109+} & \parbox{0.14\columnwidth}{row
168− & 12.0
110+} & \parbox{0.16\columnwidth}{12.0
169− & Example of a row that spans multiple lines.
111+} & \parbox{0.34\columnwidth}{Example of a row that spans multiple lines.
170−\\
112+}\\
171−Second
113+\parbox{0.15\columnwidth}{Second
172− & row
114+} & \parbox{0.14\columnwidth}{row
173− & 5.0
115+} & \parbox{0.16\columnwidth}{5.0
174− & Here's another one. Note the blank line between rows.
116+} & \parbox{0.34\columnwidth}{Here's another one. Note the blank line between
117+rows.
175−\\
118+}\\
176\end{tabular}
119\end{tabular}
177\end{center}
120\end{center}
178
121