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.
This commit is contained in:
parent
bb11f5fb86
commit
d7b5def287
3 changed files with 92 additions and 6 deletions
|
@ -245,13 +245,17 @@ blockToMs opts (Table _ blkCapt specs thead tbody tfoot) =
|
||||||
aligncode AlignDefault = "l"
|
aligncode AlignDefault = "l"
|
||||||
in do
|
in do
|
||||||
caption' <- inlineListToMs' opts caption
|
caption' <- inlineListToMs' opts caption
|
||||||
let iwidths = if all (== 0) widths
|
let isSimple = all (== 0) widths
|
||||||
then repeat ""
|
let totalWidth = 70
|
||||||
else map (T.pack . printf "w(%0.1fn)" . (70 *)) widths
|
|
||||||
-- 78n default width - 8n indent = 70n
|
-- 78n default width - 8n indent = 70n
|
||||||
let coldescriptions = literal $ T.unwords
|
let coldescriptions = literal $ T.unwords
|
||||||
(zipWith (\align width -> aligncode align <> width)
|
(zipWith (\align width -> aligncode align <>
|
||||||
alignments iwidths) <> "."
|
if width == 0
|
||||||
|
then ""
|
||||||
|
else T.pack $
|
||||||
|
printf "w(%0.1fn)"
|
||||||
|
(totalWidth * width))
|
||||||
|
alignments widths) <> "."
|
||||||
colheadings <- mapM (blockListToMs opts) headers
|
colheadings <- mapM (blockListToMs opts) headers
|
||||||
let makeRow cols = literal "T{" $$
|
let makeRow cols = literal "T{" $$
|
||||||
vcat (intersperse (literal "T}\tT{") cols) $$
|
vcat (intersperse (literal "T}\tT{") cols) $$
|
||||||
|
@ -260,13 +264,25 @@ blockToMs opts (Table _ blkCapt specs thead tbody tfoot) =
|
||||||
then empty
|
then empty
|
||||||
else makeRow colheadings $$ char '_'
|
else makeRow colheadings $$ char '_'
|
||||||
body <- mapM (\row -> do
|
body <- mapM (\row -> do
|
||||||
cols <- mapM (blockListToMs opts) row
|
cols <- mapM (\(cell, w) ->
|
||||||
|
(if isSimple
|
||||||
|
then id
|
||||||
|
else (literal (".nr LL " <>
|
||||||
|
T.pack (printf "%0.1fn"
|
||||||
|
(w * totalWidth))) $$)) <$>
|
||||||
|
blockListToMs opts cell) (zip row widths)
|
||||||
return $ makeRow cols) rows
|
return $ makeRow cols) rows
|
||||||
setFirstPara
|
setFirstPara
|
||||||
return $ literal ".PP" $$ caption' $$
|
return $ literal ".PP" $$ caption' $$
|
||||||
literal ".na" $$ -- we don't want justification in table cells
|
literal ".na" $$ -- we don't want justification in table cells
|
||||||
|
(if isSimple
|
||||||
|
then ""
|
||||||
|
else ".nr LLold \\n[LL]") $$
|
||||||
literal ".TS" $$ literal "delim(@@) tab(\t);" $$ coldescriptions $$
|
literal ".TS" $$ literal "delim(@@) tab(\t);" $$ coldescriptions $$
|
||||||
colheadings' $$ vcat body $$ literal ".TE" $$
|
colheadings' $$ vcat body $$ literal ".TE" $$
|
||||||
|
(if isSimple
|
||||||
|
then ""
|
||||||
|
else ".nr LL \\n[LLold]") $$
|
||||||
literal ".ad"
|
literal ".ad"
|
||||||
|
|
||||||
blockToMs opts (BulletList items) = do
|
blockToMs opts (BulletList items) = do
|
||||||
|
|
40
test/command/7288.md
Normal file
40
test/command/7288.md
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
```
|
||||||
|
% pandoc -f rst -t ms
|
||||||
|
.. list-table::
|
||||||
|
:widths: 50 50
|
||||||
|
:header-rows: 1
|
||||||
|
|
||||||
|
* - Left
|
||||||
|
- Right
|
||||||
|
* - Long text that should be easy to break up into multiple lines
|
||||||
|
- Another long text that should be easy to break up into multiple lines
|
||||||
|
|
||||||
|
Bar
|
||||||
|
^D
|
||||||
|
.PP
|
||||||
|
.na
|
||||||
|
.nr LLold \n[LL]
|
||||||
|
.TS
|
||||||
|
delim(@@) tab( );
|
||||||
|
lw(35.0n) lw(35.0n).
|
||||||
|
T{
|
||||||
|
Left
|
||||||
|
T} T{
|
||||||
|
Right
|
||||||
|
T}
|
||||||
|
_
|
||||||
|
T{
|
||||||
|
.nr LL 35.0n
|
||||||
|
.LP
|
||||||
|
Long text that should be easy to break up into multiple lines
|
||||||
|
T} T{
|
||||||
|
.nr LL 35.0n
|
||||||
|
.PP
|
||||||
|
Another long text that should be easy to break up into multiple lines
|
||||||
|
.PP
|
||||||
|
Bar
|
||||||
|
T}
|
||||||
|
.TE
|
||||||
|
.nr LL \n[LLold]
|
||||||
|
.ad
|
||||||
|
```
|
|
@ -143,6 +143,7 @@ Multiline table with caption:
|
||||||
.PP
|
.PP
|
||||||
Here\[cq]s the caption. It may span multiple lines.
|
Here\[cq]s the caption. It may span multiple lines.
|
||||||
.na
|
.na
|
||||||
|
.nr LLold \n[LL]
|
||||||
.TS
|
.TS
|
||||||
delim(@@) tab( );
|
delim(@@) tab( );
|
||||||
cw(10.5n) lw(9.6n) rw(11.4n) lw(24.5n).
|
cw(10.5n) lw(9.6n) rw(11.4n) lw(24.5n).
|
||||||
|
@ -157,30 +158,40 @@ Default aligned
|
||||||
T}
|
T}
|
||||||
_
|
_
|
||||||
T{
|
T{
|
||||||
|
.nr LL 10.5n
|
||||||
First
|
First
|
||||||
T} T{
|
T} T{
|
||||||
|
.nr LL 9.6n
|
||||||
row
|
row
|
||||||
T} T{
|
T} T{
|
||||||
|
.nr LL 11.4n
|
||||||
12.0
|
12.0
|
||||||
T} T{
|
T} T{
|
||||||
|
.nr LL 24.5n
|
||||||
Example of a row that spans multiple lines.
|
Example of a row that spans multiple lines.
|
||||||
T}
|
T}
|
||||||
T{
|
T{
|
||||||
|
.nr LL 10.5n
|
||||||
Second
|
Second
|
||||||
T} T{
|
T} T{
|
||||||
|
.nr LL 9.6n
|
||||||
row
|
row
|
||||||
T} T{
|
T} T{
|
||||||
|
.nr LL 11.4n
|
||||||
5.0
|
5.0
|
||||||
T} T{
|
T} T{
|
||||||
|
.nr LL 24.5n
|
||||||
Here\[cq]s another one.
|
Here\[cq]s another one.
|
||||||
Note the blank line between rows.
|
Note the blank line between rows.
|
||||||
T}
|
T}
|
||||||
.TE
|
.TE
|
||||||
|
.nr LL \n[LLold]
|
||||||
.ad
|
.ad
|
||||||
.LP
|
.LP
|
||||||
Multiline table without caption:
|
Multiline table without caption:
|
||||||
.PP
|
.PP
|
||||||
.na
|
.na
|
||||||
|
.nr LLold \n[LL]
|
||||||
.TS
|
.TS
|
||||||
delim(@@) tab( );
|
delim(@@) tab( );
|
||||||
cw(10.5n) lw(9.6n) rw(11.4n) lw(24.5n).
|
cw(10.5n) lw(9.6n) rw(11.4n) lw(24.5n).
|
||||||
|
@ -195,25 +206,34 @@ Default aligned
|
||||||
T}
|
T}
|
||||||
_
|
_
|
||||||
T{
|
T{
|
||||||
|
.nr LL 10.5n
|
||||||
First
|
First
|
||||||
T} T{
|
T} T{
|
||||||
|
.nr LL 9.6n
|
||||||
row
|
row
|
||||||
T} T{
|
T} T{
|
||||||
|
.nr LL 11.4n
|
||||||
12.0
|
12.0
|
||||||
T} T{
|
T} T{
|
||||||
|
.nr LL 24.5n
|
||||||
Example of a row that spans multiple lines.
|
Example of a row that spans multiple lines.
|
||||||
T}
|
T}
|
||||||
T{
|
T{
|
||||||
|
.nr LL 10.5n
|
||||||
Second
|
Second
|
||||||
T} T{
|
T} T{
|
||||||
|
.nr LL 9.6n
|
||||||
row
|
row
|
||||||
T} T{
|
T} T{
|
||||||
|
.nr LL 11.4n
|
||||||
5.0
|
5.0
|
||||||
T} T{
|
T} T{
|
||||||
|
.nr LL 24.5n
|
||||||
Here\[cq]s another one.
|
Here\[cq]s another one.
|
||||||
Note the blank line between rows.
|
Note the blank line between rows.
|
||||||
T}
|
T}
|
||||||
.TE
|
.TE
|
||||||
|
.nr LL \n[LLold]
|
||||||
.ad
|
.ad
|
||||||
.LP
|
.LP
|
||||||
Table without column headers:
|
Table without column headers:
|
||||||
|
@ -255,27 +275,37 @@ T}
|
||||||
Multiline table without column headers:
|
Multiline table without column headers:
|
||||||
.PP
|
.PP
|
||||||
.na
|
.na
|
||||||
|
.nr LLold \n[LL]
|
||||||
.TS
|
.TS
|
||||||
delim(@@) tab( );
|
delim(@@) tab( );
|
||||||
cw(10.5n) lw(9.6n) rw(11.4n) lw(24.5n).
|
cw(10.5n) lw(9.6n) rw(11.4n) lw(24.5n).
|
||||||
T{
|
T{
|
||||||
|
.nr LL 10.5n
|
||||||
First
|
First
|
||||||
T} T{
|
T} T{
|
||||||
|
.nr LL 9.6n
|
||||||
row
|
row
|
||||||
T} T{
|
T} T{
|
||||||
|
.nr LL 11.4n
|
||||||
12.0
|
12.0
|
||||||
T} T{
|
T} T{
|
||||||
|
.nr LL 24.5n
|
||||||
Example of a row that spans multiple lines.
|
Example of a row that spans multiple lines.
|
||||||
T}
|
T}
|
||||||
T{
|
T{
|
||||||
|
.nr LL 10.5n
|
||||||
Second
|
Second
|
||||||
T} T{
|
T} T{
|
||||||
|
.nr LL 9.6n
|
||||||
row
|
row
|
||||||
T} T{
|
T} T{
|
||||||
|
.nr LL 11.4n
|
||||||
5.0
|
5.0
|
||||||
T} T{
|
T} T{
|
||||||
|
.nr LL 24.5n
|
||||||
Here\[cq]s another one.
|
Here\[cq]s another one.
|
||||||
Note the blank line between rows.
|
Note the blank line between rows.
|
||||||
T}
|
T}
|
||||||
.TE
|
.TE
|
||||||
|
.nr LL \n[LLold]
|
||||||
.ad
|
.ad
|
||||||
|
|
Loading…
Add table
Reference in a new issue