@@ -774,9 +774,13 @@ data OrgTableRow = OrgContentRow (F [Blocks])
774774 | OrgAlignRow [Alignment]
775775 | OrgHlineRow
776776
777+-- OrgTable is strongly related to the pandoc table ADT. Using the same
778+-- (i.e. pandoc-global) ADT would mean that the reader would break if the
779+-- global structure was to be changed, which would be bad. The final table
780+-- should be generated using a builder function. Column widths aren't
781+-- implemented yet, so they are not tracked here.
777782data OrgTable = OrgTable
778− { orgTableColumns :: Int
779− , orgTableAlignments :: [Alignment]
783+ { orgTableAlignments :: [Alignment]
780784 , orgTableHeader :: [Blocks]
781785 , orgTableRows :: [[Blocks]]
782786 }
@@ -792,7 +796,7 @@ table = try $ do
792796orgToPandocTable :: OrgTable
793797 -> Inlines
794798 -> Blocks
795−orgToPandocTable (OrgTable _ aligns heads lns) caption =
799+orgToPandocTable (OrgTable aligns heads lns) caption =
796800 B.table caption (zip aligns $ repeat 0) heads lns
797801
798802tableStart :: OrgParser Char
@@ -840,20 +844,18 @@ tableHline = try $
840844
841845rowsToTable :: [OrgTableRow]
842846 -> F OrgTable
843−rowsToTable = foldM (flip rowToContent) zeroTable
844− where zeroTable = OrgTable 0 mempty mempty mempty
845−
846−normalizeTable :: OrgTable
847− -> OrgTable
848−normalizeTable (OrgTable cols aligns heads lns) =
849− let aligns' = fillColumns aligns AlignDefault
850− heads' = if heads == mempty
851− then mempty
852− else fillColumns heads (B.plain mempty)
853− lns' = map (`fillColumns` B.plain mempty) lns
854− fillColumns base padding = take cols $ base ++ repeat padding
855− in OrgTable cols aligns' heads' lns'
847+rowsToTable = foldM (flip rowToContent) emptyTable
848+ where emptyTable = OrgTable mempty mempty mempty
856849
850+normalizeTable :: OrgTable -> OrgTable
851+normalizeTable (OrgTable aligns heads rows) = OrgTable aligns' heads rows
852+ where
853+ refRow = if heads /= mempty
854+ then heads
855+ else if rows == mempty then mempty else head rows
856+ cols = length refRow
857+ fillColumns base padding = take cols $ base ++ repeat padding
858+ aligns' = fillColumns aligns AlignDefault
857859
858860-- One or more horizontal rules after the first content line mark the previous
859861-- line as a header. All other horizontal lines are discarded.
@@ -861,16 +863,10 @@ rowToContent :: OrgTableRow
861863 -> OrgTable
862864 -> F OrgTable
863865rowToContent OrgHlineRow t = maybeBodyToHeader t
864−rowToContent (OrgAlignRow as) t = setLongestRow as =<< setAligns as t
866+rowToContent (OrgAlignRow as) t = setAligns as t
865867rowToContent (OrgContentRow rf) t = do
866868 rs <- rf
867− setLongestRow rs =<< appendToBody rs t
868−
869−setLongestRow :: [a]
870− -> OrgTable
871− -> F OrgTable
872−setLongestRow rs t =
873− return t{ orgTableColumns = max (length rs) (orgTableColumns t) }
869+ appendToBody rs t
874870
875871maybeBodyToHeader :: OrgTable
876872 -> F OrgTable