From 9788a062233c2d18373b8e26ec695919eb78c06e Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 12 Jun 2024 03:53:00 +0100 Subject: [PATCH] fix: balcmds: don't repeat "total" and "Net:" headers in HTML output --- hledger/Hledger/Cli/Commands/Balance.hs | 3 ++- hledger/Hledger/Cli/CompoundBalanceCommand.hs | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/hledger/Hledger/Cli/Commands/Balance.hs b/hledger/Hledger/Cli/Commands/Balance.hs index 81191ed78..dc18af1ab 100644 --- a/hledger/Hledger/Cli/Commands/Balance.hs +++ b/hledger/Hledger/Cli/Commands/Balance.hs @@ -580,7 +580,8 @@ multiBalanceReportAsCsvHelper ishtml opts@ReportOpts{..} (PeriodicReport colspan where showName = accountNameDrop drop_ . prrFullName totalrows | no_total_ = mempty - | otherwise = map ("total" :) $ rowAsText opts colspans tr + | ishtml = zipWith (:) ("total":repeat "") $ rowAsText opts colspans tr + | otherwise = map ("total" :) $ rowAsText opts colspans tr rowAsText = if ishtml then multiBalanceRowAsHtmlText else multiBalanceRowAsCsvText -- | Render a multi-column balance report as HTML. diff --git a/hledger/Hledger/Cli/CompoundBalanceCommand.hs b/hledger/Hledger/Cli/CompoundBalanceCommand.hs index 456e8b87f..da95e9cc5 100644 --- a/hledger/Hledger/Cli/CompoundBalanceCommand.hs +++ b/hledger/Hledger/Cli/CompoundBalanceCommand.hs @@ -29,6 +29,7 @@ import Hledger import Hledger.Cli.Commands.Balance import Hledger.Cli.CliOptions import Hledger.Cli.Utils (unsupportedOutputFormatError, writeOutputLazyText) +import Data.Function ((&)) -- | Description of a compound balance report command, -- from which we generate the command's cmdargs mode and IO action. @@ -337,8 +338,13 @@ compoundBalanceReportAsHtml ropts cbr = ++ mtotalsrows ++ [blankrow] - totalrows | no_total_ ropts || length subreports == 1 = [] - | otherwise = multiBalanceReportHtmlFootRow ropts <$> (("Net:" :) <$> multiBalanceRowAsCsvText ropts colspans totalrow) + totalrows = + if no_total_ ropts || length subreports == 1 then [] + else + multiBalanceRowAsCsvText ropts colspans totalrow -- make a table of rendered lines of the report totals row + & zipWith (:) ("Net:":repeat "") -- insert a headings column, with Net: on the first line only + & map (multiBalanceReportHtmlFootRow ropts) -- convert to a list of HTML totals rows + in do style_ (T.unlines ["" ,"td { padding:0 0.5em; }"