Org reader: stop padding short table rows
Emacs Org-mode doesn't add any padding to table rows. The first row (header or first body row) is used to determine the column count, no other magic is performed. The org reader was padding rows to the length of the longest table row. This was done due to a misunderstanding of how Org handles tables. This feature reflected how Org-mode handles tables when pressing <TAB>. The Org exporter however, which is what the reader should implement, doesn't do any of this. So this was a mis-feature that made the reader more complex and reduced comparability. It was hence removed.
This commit is contained in:
parent
cc9a9c7150
commit
d5e4bc179c
2 changed files with 24 additions and 28 deletions
|
@ -774,9 +774,13 @@ data OrgTableRow = OrgContentRow (F [Blocks])
|
||||||
| OrgAlignRow [Alignment]
|
| OrgAlignRow [Alignment]
|
||||||
| OrgHlineRow
|
| OrgHlineRow
|
||||||
|
|
||||||
|
-- OrgTable is strongly related to the pandoc table ADT. Using the same
|
||||||
|
-- (i.e. pandoc-global) ADT would mean that the reader would break if the
|
||||||
|
-- global structure was to be changed, which would be bad. The final table
|
||||||
|
-- should be generated using a builder function. Column widths aren't
|
||||||
|
-- implemented yet, so they are not tracked here.
|
||||||
data OrgTable = OrgTable
|
data OrgTable = OrgTable
|
||||||
{ orgTableColumns :: Int
|
{ orgTableAlignments :: [Alignment]
|
||||||
, orgTableAlignments :: [Alignment]
|
|
||||||
, orgTableHeader :: [Blocks]
|
, orgTableHeader :: [Blocks]
|
||||||
, orgTableRows :: [[Blocks]]
|
, orgTableRows :: [[Blocks]]
|
||||||
}
|
}
|
||||||
|
@ -792,7 +796,7 @@ table = try $ do
|
||||||
orgToPandocTable :: OrgTable
|
orgToPandocTable :: OrgTable
|
||||||
-> Inlines
|
-> Inlines
|
||||||
-> Blocks
|
-> Blocks
|
||||||
orgToPandocTable (OrgTable _ aligns heads lns) caption =
|
orgToPandocTable (OrgTable aligns heads lns) caption =
|
||||||
B.table caption (zip aligns $ repeat 0) heads lns
|
B.table caption (zip aligns $ repeat 0) heads lns
|
||||||
|
|
||||||
tableStart :: OrgParser Char
|
tableStart :: OrgParser Char
|
||||||
|
@ -840,20 +844,18 @@ tableHline = try $
|
||||||
|
|
||||||
rowsToTable :: [OrgTableRow]
|
rowsToTable :: [OrgTableRow]
|
||||||
-> F OrgTable
|
-> F OrgTable
|
||||||
rowsToTable = foldM (flip rowToContent) zeroTable
|
rowsToTable = foldM (flip rowToContent) emptyTable
|
||||||
where zeroTable = OrgTable 0 mempty mempty mempty
|
where emptyTable = OrgTable mempty mempty mempty
|
||||||
|
|
||||||
normalizeTable :: OrgTable
|
|
||||||
-> OrgTable
|
|
||||||
normalizeTable (OrgTable cols aligns heads lns) =
|
|
||||||
let aligns' = fillColumns aligns AlignDefault
|
|
||||||
heads' = if heads == mempty
|
|
||||||
then mempty
|
|
||||||
else fillColumns heads (B.plain mempty)
|
|
||||||
lns' = map (`fillColumns` B.plain mempty) lns
|
|
||||||
fillColumns base padding = take cols $ base ++ repeat padding
|
|
||||||
in OrgTable cols aligns' heads' lns'
|
|
||||||
|
|
||||||
|
normalizeTable :: OrgTable -> OrgTable
|
||||||
|
normalizeTable (OrgTable aligns heads rows) = OrgTable aligns' heads rows
|
||||||
|
where
|
||||||
|
refRow = if heads /= mempty
|
||||||
|
then heads
|
||||||
|
else if rows == mempty then mempty else head rows
|
||||||
|
cols = length refRow
|
||||||
|
fillColumns base padding = take cols $ base ++ repeat padding
|
||||||
|
aligns' = fillColumns aligns AlignDefault
|
||||||
|
|
||||||
-- One or more horizontal rules after the first content line mark the previous
|
-- One or more horizontal rules after the first content line mark the previous
|
||||||
-- line as a header. All other horizontal lines are discarded.
|
-- line as a header. All other horizontal lines are discarded.
|
||||||
|
@ -861,16 +863,10 @@ rowToContent :: OrgTableRow
|
||||||
-> OrgTable
|
-> OrgTable
|
||||||
-> F OrgTable
|
-> F OrgTable
|
||||||
rowToContent OrgHlineRow t = maybeBodyToHeader t
|
rowToContent OrgHlineRow t = maybeBodyToHeader t
|
||||||
rowToContent (OrgAlignRow as) t = setLongestRow as =<< setAligns as t
|
rowToContent (OrgAlignRow as) t = setAligns as t
|
||||||
rowToContent (OrgContentRow rf) t = do
|
rowToContent (OrgContentRow rf) t = do
|
||||||
rs <- rf
|
rs <- rf
|
||||||
setLongestRow rs =<< appendToBody rs t
|
appendToBody rs t
|
||||||
|
|
||||||
setLongestRow :: [a]
|
|
||||||
-> OrgTable
|
|
||||||
-> F OrgTable
|
|
||||||
setLongestRow rs t =
|
|
||||||
return t{ orgTableColumns = max (length rs) (orgTableColumns t) }
|
|
||||||
|
|
||||||
maybeBodyToHeader :: OrgTable
|
maybeBodyToHeader :: OrgTable
|
||||||
-> F OrgTable
|
-> F OrgTable
|
||||||
|
|
|
@ -1024,10 +1024,10 @@ tests =
|
||||||
, "| 1 | One | foo |"
|
, "| 1 | One | foo |"
|
||||||
, "| 2"
|
, "| 2"
|
||||||
] =?>
|
] =?>
|
||||||
table "" (zip [AlignCenter, AlignRight, AlignDefault] [0, 0, 0])
|
table "" (zip [AlignCenter, AlignRight] [0, 0])
|
||||||
[ plain "Numbers", plain "Text" , plain mempty ]
|
[ plain "Numbers", plain "Text" ]
|
||||||
[ [ plain "1" , plain "One" , plain "foo" ]
|
[ [ plain "1" , plain "One" , plain "foo" ]
|
||||||
, [ plain "2" , plain mempty , plain mempty ]
|
, [ plain "2" ]
|
||||||
]
|
]
|
||||||
|
|
||||||
, "Table with caption" =:
|
, "Table with caption" =:
|
||||||
|
|
Loading…
Reference in a new issue