git.iko.soy/typeable/pandoc
on master help sign in
Ms writer: handle tables with multiple paragraphs.

Previously they overflowed the table cell width. We now set line lengths per-cell and restore them after the table has been written. Closes #7288.

commitd7b5def287aefe91f881daeecc5f72121c843b66 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 20 May 2021, 17:12 (5 years ago) parentbb11f5f
3 files changed+92−6
src/Text/Pandoc/Writers/Ms.hs+22−6 test/command/7288.md+40 test/tables.ms+30
src/Text/Pandoc/Writers/Ms.hs+22−6
@@ -245,13 +245,17 @@ blockToMs opts (Table _ blkCapt specs thead tbody tfoot) =
245245 aligncode AlignDefault = "l"
246246 in do
247247 caption' <- inlineListToMs' opts caption
248− let iwidths = if all (== 0) widths
249− then repeat ""
250− else map (T.pack . printf "w(%0.1fn)" . (70 *)) widths
248+ let isSimple = all (== 0) widths
249+ let totalWidth = 70
251250 -- 78n default width - 8n indent = 70n
252251 let coldescriptions = literal $ T.unwords
253− (zipWith (\align width -> aligncode align <> width)
254− alignments iwidths) <> "."
252+ (zipWith (\align width -> aligncode align <>
253+ if width == 0
254+ then ""
255+ else T.pack $
256+ printf "w(%0.1fn)"
257+ (totalWidth * width))
258+ alignments widths) <> "."
255259 colheadings <- mapM (blockListToMs opts) headers
256260 let makeRow cols = literal "T{" $$
257261 vcat (intersperse (literal "T}\tT{") cols) $$
@@ -260,13 +264,25 @@ blockToMs opts (Table _ blkCapt specs thead tbody tfoot) =
260264 then empty
261265 else makeRow colheadings $$ char '_'
262266 body <- mapM (\row -> do
263− cols <- mapM (blockListToMs opts) row
267+ cols <- mapM (\(cell, w) ->
268+ (if isSimple
269+ then id
270+ else (literal (".nr LL " <>
271+ T.pack (printf "%0.1fn"
272+ (w * totalWidth))) $$)) <$>
273+ blockListToMs opts cell) (zip row widths)
264274 return $ makeRow cols) rows
265275 setFirstPara
266276 return $ literal ".PP" $$ caption' $$
267277 literal ".na" $$ -- we don't want justification in table cells
278+ (if isSimple
279+ then ""
280+ else ".nr LLold \\n[LL]") $$
268281 literal ".TS" $$ literal "delim(@@) tab(\t);" $$ coldescriptions $$
269282 colheadings' $$ vcat body $$ literal ".TE" $$
283+ (if isSimple
284+ then ""
285+ else ".nr LL \\n[LLold]") $$
270286 literal ".ad"
271287
272288blockToMs opts (BulletList items) = do
test/command/7288.mdnew file+40
@@ -0,0 +1,40 @@
1+```
2+% pandoc -f rst -t ms
3+.. list-table::
4+ :widths: 50 50
5+ :header-rows: 1
6+
7+ * - Left
8+ - Right
9+ * - Long text that should be easy to break up into multiple lines
10+ - Another long text that should be easy to break up into multiple lines
11+
12+ Bar
13+^D
14+.PP
15+.na
16+.nr LLold \n[LL]
17+.TS
18+delim(@@) tab( );
19+lw(35.0n) lw(35.0n).
20+T{
21+Left
22+T} T{
23+Right
24+T}
25+_
26+T{
27+.nr LL 35.0n
28+.LP
29+Long text that should be easy to break up into multiple lines
30+T} T{
31+.nr LL 35.0n
32+.PP
33+Another long text that should be easy to break up into multiple lines
34+.PP
35+Bar
36+T}
37+.TE
38+.nr LL \n[LLold]
39+.ad
40+```
test/tables.ms+30
@@ -143,6 +143,7 @@ Multiline table with caption:
143143.PP
144144Here\[cq]s the caption. It may span multiple lines.
145145.na
146+.nr LLold \n[LL]
146147.TS
147148delim(@@) tab( );
148149cw(10.5n) lw(9.6n) rw(11.4n) lw(24.5n).
@@ -157,30 +158,40 @@ Default aligned
157158T}
158159_
159160T{
161+.nr LL 10.5n
160162First
161163T} T{
164+.nr LL 9.6n
162165row
163166T} T{
167+.nr LL 11.4n
16416812.0
165169T} T{
170+.nr LL 24.5n
166171Example of a row that spans multiple lines.
167172T}
168173T{
174+.nr LL 10.5n
169175Second
170176T} T{
177+.nr LL 9.6n
171178row
172179T} T{
180+.nr LL 11.4n
1731815.0
174182T} T{
183+.nr LL 24.5n
175184Here\[cq]s another one.
176185Note the blank line between rows.
177186T}
178187.TE
188+.nr LL \n[LLold]
179189.ad
180190.LP
181191Multiline table without caption:
182192.PP
183193.na
194+.nr LLold \n[LL]
184195.TS
185196delim(@@) tab( );
186197cw(10.5n) lw(9.6n) rw(11.4n) lw(24.5n).
@@ -195,25 +206,34 @@ Default aligned
195206T}
196207_
197208T{
209+.nr LL 10.5n
198210First
199211T} T{
212+.nr LL 9.6n
200213row
201214T} T{
215+.nr LL 11.4n
20221612.0
203217T} T{
218+.nr LL 24.5n
204219Example of a row that spans multiple lines.
205220T}
206221T{
222+.nr LL 10.5n
207223Second
208224T} T{
225+.nr LL 9.6n
209226row
210227T} T{
228+.nr LL 11.4n
2112295.0
212230T} T{
231+.nr LL 24.5n
213232Here\[cq]s another one.
214233Note the blank line between rows.
215234T}
216235.TE
236+.nr LL \n[LLold]
217237.ad
218238.LP
219239Table without column headers:
@@ -255,27 +275,37 @@ T}
255275Multiline table without column headers:
256276.PP
257277.na
278+.nr LLold \n[LL]
258279.TS
259280delim(@@) tab( );
260281cw(10.5n) lw(9.6n) rw(11.4n) lw(24.5n).
261282T{
283+.nr LL 10.5n
262284First
263285T} T{
286+.nr LL 9.6n
264287row
265288T} T{
289+.nr LL 11.4n
26629012.0
267291T} T{
292+.nr LL 24.5n
268293Example of a row that spans multiple lines.
269294T}
270295T{
296+.nr LL 10.5n
271297Second
272298T} T{
299+.nr LL 9.6n
273300row
274301T} T{
302+.nr LL 11.4n
2753035.0
276304T} T{
305+.nr LL 24.5n
277306Here\[cq]s another one.
278307Note the blank line between rows.
279308T}
280309.TE
310+.nr LL \n[LLold]
281311.ad