Skip to content

Commit e2f2a22

Browse files
jokespersimonmichael
authored andcommitted
fix: html: Nested tables resulting in broken HTML on export
A HTML export results in a table which has a stylesheet and another table nested inside. This is not valid HTML and gets auto corrected by closing the first table and opening another table. The result is the heading of the table can expand further than the remaining table. This results in a few notable changes: - The date is in a far bigger cell and it's very noticeable it's centered compared to the amounts (we may want to right align the date, though I don't have any particular thoughts about this) - We no longer have two consecutive lines with black background and the start - The table is as big as the heading (+ the default left margin)
1 parent 6111706 commit e2f2a22

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

hledger/Hledger/Cli/CompoundBalanceCommand.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Hledger.Cli.CompoundBalanceCommand (
1616

1717
import Control.Monad (guard)
1818
import Data.Bifunctor (second)
19+
import Data.Foldable (traverse_)
1920
import Data.Function ((&))
2021
import Data.List.NonEmpty (NonEmpty((:|)))
2122
import Data.Maybe (fromMaybe, mapMaybe, maybeToList)
@@ -36,7 +37,7 @@ import Hledger.Cli.Commands.Balance
3637
import Hledger.Cli.CliOptions
3738
import Hledger.Cli.Utils (unsupportedOutputFormatError, writeOutputLazyText)
3839
import Hledger.Write.Csv (CSV, printCSV, printTSV)
39-
import Hledger.Write.Html (htmlAsLazyText, styledTableHtml, Html)
40+
import Hledger.Write.Html (formatRow, htmlAsLazyText, Html)
4041
import Hledger.Write.Html.Attribute (stylesheet, tableStyle, alignleft)
4142
import Hledger.Write.Ods (printFods)
4243
import Hledger.Write.Spreadsheet qualified as Spr
@@ -339,7 +340,8 @@ compoundBalanceReportAsHtml ropts cbr =
339340
]
340341
table_ $ do
341342
tr_ $ th_ [colspanattr, style_ alignleft] $ h2_ $ toHtml title
342-
styledTableHtml $ NonEmpty.toList $ fmap (map (fmap L.toHtml)) cells
343+
-- Do not use `styledTableHtml` here since that leads to nested `<table>`s.
344+
traverse_ formatRow $ fmap (map (fmap L.toHtml)) cells
343345

344346
-- | Render a compound balance report as Spreadsheet.
345347
compoundBalanceReportAsSpreadsheet ::

0 commit comments

Comments
 (0)