mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-28 17:20:47 +08:00
Markdown writer: don't try to align columns in pipe tables...
...with lines greater than COLUMNS. The alignment just reduces readibility when the lines soft wrap.
This commit is contained in:
@@ -36,15 +36,18 @@ pipeTable :: PandocMonad m
|
||||
-> MD m (Doc Text)
|
||||
pipeTable opts headless aligns widths rawHeaders rawRows = do
|
||||
let sp = literal " "
|
||||
let blockFor AlignLeft x y = lblock (x + 2) (sp <> y) <> lblock 0 empty
|
||||
blockFor AlignCenter x y = cblock (x + 2) (sp <> y <> sp) <> lblock 0 empty
|
||||
blockFor AlignRight x y = rblock (x + 2) (y <> sp) <> lblock 0 empty
|
||||
blockFor _ x y = lblock (x + 2) (sp <> y) <> lblock 0 empty
|
||||
let contentWidths = map (max 3 . maybe 3 maximum . nonEmpty . map offset) $
|
||||
transpose (rawHeaders : rawRows)
|
||||
let colwidth = writerColumns opts
|
||||
let numcols = length contentWidths
|
||||
let maxwidth = sum contentWidths
|
||||
-- if cell contents are > COLUMNS, adding padding looks bad
|
||||
let pad = maxwidth <= writerColumns opts
|
||||
let blockFor _ _ y | not pad = sp <> y <> sp <> lblock 0 empty
|
||||
blockFor AlignLeft x y = lblock (x + 2) (sp <> y) <> lblock 0 empty
|
||||
blockFor AlignCenter x y = cblock (x + 2) (sp <> y <> sp) <> lblock 0 empty
|
||||
blockFor AlignRight x y = rblock (x + 2) (y <> sp) <> lblock 0 empty
|
||||
blockFor AlignDefault x y = lblock (x + 2) (sp <> y) <> lblock 0 empty
|
||||
variant <- asks envVariant
|
||||
let pipeWidths = if variant == Markdown &&
|
||||
not (all (== 0) widths) &&
|
||||
@@ -54,7 +57,9 @@ pipeTable opts headless aligns widths rawHeaders rawRows = do
|
||||
floor .
|
||||
(* fromIntegral (colwidth - (numcols +1))))
|
||||
widths
|
||||
else contentWidths
|
||||
else if pad
|
||||
then contentWidths
|
||||
else map (const 2) widths
|
||||
let torow cs = nowrap $ literal "|" <>
|
||||
hcat (intersperse (literal "|") $
|
||||
zipWith3 blockFor aligns contentWidths (map chomp cs))
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|--------------|-------|--------------------------------------------------------------------------|
|
||||
| aaaaaaaaaaaa | | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
^D
|
||||
| aaaaaaaaaaaa | bbbbb | ccccccccccc |
|
||||
| aaaaaaaaaaaa | bbbbb | ccccccccccc |
|
||||
|------------|-------|------------------------------------------------------|
|
||||
| aaaaaaaaaaaa | | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| aaaaaaaaaaaa | | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
```
|
||||
|
||||
```
|
||||
@@ -15,9 +15,9 @@
|
||||
|--------------|-------|--------------------------------------------------------------------------|
|
||||
| aaaaaaaaaaaa | | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
^D
|
||||
| aaaaaaaaaaaa | bbbbb | ccccccccccc |
|
||||
| aaaaaaaaaaaa | bbbbb | ccccccccccc |
|
||||
|------------|-------|------------------------------------------------------|
|
||||
| aaaaaaaaaaaa | | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| aaaaaaaaaaaa | | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
```
|
||||
|
||||
```
|
||||
@@ -26,7 +26,7 @@
|
||||
|--------------|-------|--------------------------------------------------------------------------|
|
||||
| aaaaaaaaaaaa | | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
^D
|
||||
| aaaaaaaaaaaa | bbbbb | ccccccccccc |
|
||||
|--------------|-------|--------------------------------------------------------------------------|
|
||||
| aaaaaaaaaaaa | | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
| aaaaaaaaaaaa | bbbbb | ccccccccccc |
|
||||
|----|----|----|
|
||||
| aaaaaaaaaaaa | | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
|
||||
```
|
||||
|
||||
@@ -23,9 +23,9 @@ sit amet, rhoncus porta, malesuada elementum, nisi.</td>
|
||||
</tbody>
|
||||
</table>
|
||||
^D
|
||||
| aaa | bbb | ccc |
|
||||
| aaa | bbb | ccc |
|
||||
|---------------|------------------------------------------|---------------|
|
||||
| Consequat nisi sit amet nibh. Nunc mi tortor, tristique sit amet, rhoncus porta, malesuada elementum, nisi. | | ccc |
|
||||
| Consequat nisi sit amet nibh. Nunc mi tortor, tristique sit amet, rhoncus porta, malesuada elementum, nisi. | | ccc |
|
||||
|
||||
```
|
||||
|
||||
@@ -45,9 +45,9 @@ sit amet, rhoncus porta, malesuada elementum, nisi.</td>
|
||||
</tr>
|
||||
</table>
|
||||
^D
|
||||
| aaa | bbb | ccc |
|
||||
|-------------------------------------------------------------------------------------------------------------|-----|-----|
|
||||
| Consequat nisi sit amet nibh. Nunc mi tortor, tristique sit amet, rhoncus porta, malesuada elementum, nisi. | | ccc |
|
||||
| aaa | bbb | ccc |
|
||||
|----|----|----|
|
||||
| Consequat nisi sit amet nibh. Nunc mi tortor, tristique sit amet, rhoncus porta, malesuada elementum, nisi. | | ccc |
|
||||
|
||||
```
|
||||
|
||||
@@ -76,8 +76,8 @@ sit amet, rhoncus porta, malesuada elementum, nisi.</td>
|
||||
</tbody>
|
||||
</table>
|
||||
^D
|
||||
| aaa | bbb | ccc |
|
||||
|-------------------------------------------------------------------------------------------------------------|-----|-----|
|
||||
| aaa | bbb | ccc |
|
||||
|----|----|----|
|
||||
| Consequat nisi sit amet nibh. Nunc mi tortor, tristique sit amet, rhoncus porta, malesuada elementum, nisi. | bbb | ccc |
|
||||
|
||||
```
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|V1 |V2 |V3 |V4 |V5 |V6 |V7 |V8 |V9 |V10 |V11 |V12 |V13 |V14 |V15 |V16 |V17 |V18 |V19 |V20 |V21 |V22 |V23 |V24 |V25 |V26 |V27 |V28 |V29 |V30 |V31 |V32 |V33 |V34 |V35 |V36 |V37 |V38 |V39 |V40 |V41 |V42 |V43 |V44 |V45 |V46 |V47 |V48 |V49 |V50 |V51 |V52 |V53 |V54 |V55 |V56 |V57 |V58 |V59 |V60 |V61 |V62 |V63 |V64 |V65 |V66 |V67 |V68 |V69 |V70 |V71 |V72 |
|
||||
|:--|:--|:--|:--|:--|:--|:--|:--|:--|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|
|
||||
^D
|
||||
| V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 | V11 | V12 | V13 | V14 | V15 | V16 | V17 | V18 | V19 | V20 | V21 | V22 | V23 | V24 | V25 | V26 | V27 | V28 | V29 | V30 | V31 | V32 | V33 | V34 | V35 | V36 | V37 | V38 | V39 | V40 | V41 | V42 | V43 | V44 | V45 | V46 | V47 | V48 | V49 | V50 | V51 | V52 | V53 | V54 | V55 | V56 | V57 | V58 | V59 | V60 | V61 | V62 | V63 | V64 | V65 | V66 | V67 | V68 | V69 | V70 | V71 | V72 |
|
||||
| V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 | V11 | V12 | V13 | V14 | V15 | V16 | V17 | V18 | V19 | V20 | V21 | V22 | V23 | V24 | V25 | V26 | V27 | V28 | V29 | V30 | V31 | V32 | V33 | V34 | V35 | V36 | V37 | V38 | V39 | V40 | V41 | V42 | V43 | V44 | V45 | V46 | V47 | V48 | V49 | V50 | V51 | V52 | V53 | V54 | V55 | V56 | V57 | V58 | V59 | V60 | V61 | V62 | V63 | V64 | V65 | V66 | V67 | V68 | V69 | V70 | V71 | V72 |
|
||||
|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|
|
||||
```
|
||||
|
||||
+8
-8
@@ -28,19 +28,19 @@ Demonstration of simple table syntax.
|
||||
|
||||
Multiline table with caption:
|
||||
|
||||
| Centered Header | Left Aligned | Right Aligned | Default aligned |
|
||||
|:---------------:|:-------------|--------------:|:------------------------------------------------------|
|
||||
| First | row | 12.0 | Example of a row that spans multiple lines. |
|
||||
| Second | row | 5.0 | Here’s another one. Note the blank line between rows. |
|
||||
| Centered Header | Left Aligned | Right Aligned | Default aligned |
|
||||
|:--:|:---|---:|:---|
|
||||
| First | row | 12.0 | Example of a row that spans multiple lines. |
|
||||
| Second | row | 5.0 | Here’s another one. Note the blank line between rows. |
|
||||
|
||||
Here’s the caption. It may span multiple lines.
|
||||
|
||||
Multiline table without caption:
|
||||
|
||||
| Centered Header | Left Aligned | Right Aligned | Default aligned |
|
||||
|:---------------:|:-------------|--------------:|:------------------------------------------------------|
|
||||
| First | row | 12.0 | Example of a row that spans multiple lines. |
|
||||
| Second | row | 5.0 | Here’s another one. Note the blank line between rows. |
|
||||
| Centered Header | Left Aligned | Right Aligned | Default aligned |
|
||||
|:--:|:---|---:|:---|
|
||||
| First | row | 12.0 | Example of a row that spans multiple lines. |
|
||||
| Second | row | 5.0 | Here’s another one. Note the blank line between rows. |
|
||||
|
||||
Table without column headers:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user