@@ -774,9 +774,13 @@ data OrgTableRow = OrgContentRow (F [Blocks])
774 | OrgAlignRow [Alignment]
774 | OrgAlignRow [Alignment]
775 | OrgHlineRow
775 | OrgHlineRow
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.
777data OrgTable = OrgTable
782data OrgTable = OrgTable
778− { orgTableColumns :: Int
779− , orgTableAlignments :: [Alignment]
783+ { orgTableAlignments :: [Alignment]
780 , orgTableHeader :: [Blocks]
784 , orgTableHeader :: [Blocks]
781 , orgTableRows :: [[Blocks]]
785 , orgTableRows :: [[Blocks]]
@@ -792,7 +796,7 @@ table = try $ do
792orgToPandocTable :: OrgTable
796orgToPandocTable :: OrgTable
793 -> Inlines
797 -> Inlines
794 -> Blocks
798 -> Blocks
795−orgToPandocTable (OrgTable _ aligns heads lns) caption =
799+orgToPandocTable (OrgTable aligns heads lns) caption =
796 B.table caption (zip aligns $ repeat 0) heads lns
800 B.table caption (zip aligns $ repeat 0) heads lns
798tableStart :: OrgParser Char
802tableStart :: OrgParser Char
@@ -840,20 +844,18 @@ tableHline = try $
841rowsToTable :: [OrgTableRow]
845rowsToTable :: [OrgTableRow]
842 -> F OrgTable
846 -> F OrgTable
843−rowsToTable = foldM (flip rowToContent) zeroTable
847+rowsToTable = foldM (flip rowToContent) emptyTable
844− where zeroTable = OrgTable 0 mempty mempty mempty
848+ where emptyTable = OrgTable mempty mempty mempty
846−normalizeTable :: OrgTable
848−normalizeTable (OrgTable cols aligns heads lns) =
849− let aligns' = fillColumns aligns AlignDefault
850− heads' = if heads == 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'
850+normalizeTable :: OrgTable -> OrgTable
851+normalizeTable (OrgTable aligns heads rows) = OrgTable aligns' heads rows
853+ refRow = if heads /= mempty
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
858-- One or more horizontal rules after the first content line mark the previous
860-- One or more horizontal rules after the first content line mark the previous
859-- line as a header. All other horizontal lines are discarded.
861-- line as a header. All other horizontal lines are discarded.
@@ -861,16 +863,10 @@ rowToContent :: OrgTableRow
861 -> OrgTable
863 -> OrgTable
862 -> F OrgTable
864 -> F OrgTable
863rowToContent OrgHlineRow t = maybeBodyToHeader t
865rowToContent OrgHlineRow t = maybeBodyToHeader t
864−rowToContent (OrgAlignRow as) t = setLongestRow as =<< setAligns as t
866+rowToContent (OrgAlignRow as) t = setAligns as t
865rowToContent (OrgContentRow rf) t = do
867rowToContent (OrgContentRow rf) t = do
867− setLongestRow rs =<< appendToBody rs t
869+ appendToBody rs t
873− return t{ orgTableColumns = max (length rs) (orgTableColumns t) }
875maybeBodyToHeader :: OrgTable
871maybeBodyToHeader :: OrgTable
876 -> F OrgTable
872 -> F OrgTable