From e2f2a22346e3311d85746083df9d5a086c7d4dba Mon Sep 17 00:00:00 2001 From: Joschua Kesper Date: Thu, 23 Oct 2025 23:07:48 +0200 Subject: [PATCH] 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) --- hledger/Hledger/Cli/CompoundBalanceCommand.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hledger/Hledger/Cli/CompoundBalanceCommand.hs b/hledger/Hledger/Cli/CompoundBalanceCommand.hs index 9ed423264..a6287d9e0 100644 --- a/hledger/Hledger/Cli/CompoundBalanceCommand.hs +++ b/hledger/Hledger/Cli/CompoundBalanceCommand.hs @@ -16,6 +16,7 @@ module Hledger.Cli.CompoundBalanceCommand ( import Control.Monad (guard) import Data.Bifunctor (second) +import Data.Foldable (traverse_) import Data.Function ((&)) import Data.List.NonEmpty (NonEmpty((:|))) import Data.Maybe (fromMaybe, mapMaybe, maybeToList) @@ -36,7 +37,7 @@ import Hledger.Cli.Commands.Balance import Hledger.Cli.CliOptions import Hledger.Cli.Utils (unsupportedOutputFormatError, writeOutputLazyText) import Hledger.Write.Csv (CSV, printCSV, printTSV) -import Hledger.Write.Html (htmlAsLazyText, styledTableHtml, Html) +import Hledger.Write.Html (formatRow, htmlAsLazyText, Html) import Hledger.Write.Html.Attribute (stylesheet, tableStyle, alignleft) import Hledger.Write.Ods (printFods) import Hledger.Write.Spreadsheet qualified as Spr @@ -339,7 +340,8 @@ compoundBalanceReportAsHtml ropts cbr = ] table_ $ do tr_ $ th_ [colspanattr, style_ alignleft] $ h2_ $ toHtml title - styledTableHtml $ NonEmpty.toList $ fmap (map (fmap L.toHtml)) cells + -- Do not use `styledTableHtml` here since that leads to nested ``s. + traverse_ formatRow $ fmap (map (fmap L.toHtml)) cells -- | Render a compound balance report as Spreadsheet. compoundBalanceReportAsSpreadsheet ::