@@ -844,7 +844,7 @@ tableHline = try $
845rowsToTable :: [OrgTableRow]
845rowsToTable :: [OrgTableRow]
846 -> F OrgTable
846 -> F OrgTable
847−rowsToTable = foldM (flip rowToContent) emptyTable
847+rowsToTable = foldM rowToContent emptyTable
848 where emptyTable = OrgTable mempty mempty mempty
848 where emptyTable = OrgTable mempty mempty mempty
850normalizeTable :: OrgTable -> OrgTable
850normalizeTable :: OrgTable -> OrgTable
@@ -859,31 +859,31 @@ normalizeTable (OrgTable aligns heads rows) = OrgTable aligns' heads rows
860-- 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
861-- line as a header. All other horizontal lines are discarded.
861-- line as a header. All other horizontal lines are discarded.
862−rowToContent :: OrgTableRow
862+rowToContent :: OrgTable
863− -> OrgTable
863+ -> OrgTableRow
864 -> F OrgTable
864 -> F OrgTable
865−rowToContent OrgHlineRow t = maybeBodyToHeader t
865+rowToContent orgTable row =
867+ OrgHlineRow -> return singleRowPromotedToHeader
866−rowToContent (OrgAlignRow as) t = setAligns as t
868+ OrgAlignRow as -> return . setAligns $ as
867−rowToContent (OrgContentRow rf) t = do
869− appendToBody rs t
869+ OrgContentRow cs -> appendToBody cs
871−maybeBodyToHeader :: OrgTable
871+ singleRowPromotedToHeader :: OrgTable
872− -> F OrgTable
872+ singleRowPromotedToHeader = case orgTable of
873−maybeBodyToHeader t = case t of
874− OrgTable{ orgTableHeader = [], orgTableRows = b:[] } ->
873+ OrgTable{ orgTableHeader = [], orgTableRows = b:[] } ->
875− return t{ orgTableHeader = b , orgTableRows = [] }
874+ orgTable{ orgTableHeader = b , orgTableRows = [] }
876− _ -> return t
875+ _ -> orgTable
878−appendToBody :: [Blocks]
881−appendToBody r t = return t{ orgTableRows = orgTableRows t ++ [r] }
883−setAligns :: [Alignment]
877+ setAligns :: [Alignment] -> OrgTable
886−setAligns aligns t = return $ t{ orgTableAlignments = aligns }
878+ setAligns aligns = orgTable{ orgTableAlignments = aligns }
880+ appendToBody :: F [Blocks] -> F OrgTable
881+ appendToBody frow = do
883+ let oldRows = orgTableRows orgTable
884+ -- NOTE: This is an inefficient O(n) operation. This should be changed
885+ -- if performance ever becomes a problem.
886+ return orgTable{ orgTableRows = oldRows ++ [newRow] }