{-# LANGUAGE OverloadedStrings #-}
module Hledger.Write.Html (
Html,
toHtml,
Lines(..),
borderClasses,
formatCell,
formatRow,
formatTitle,
htmlAsText,
htmlAsLazyText,
nl,
styledTableHtml,
titledTableHtml,
tests_Hledger_Write_Html
) where
import Control.Monad (unless)
import Data.Foldable (traverse_)
import Data.List (intersperse)
import Data.Text (Text)
import Data.Text qualified as Text
import Data.Text.Lazy qualified as TL
import Text.Blaze.Html5 (Html, toHtml, (!))
import Text.Blaze.Html5 qualified as H
import Text.Blaze.Html5.Attributes qualified as A
import Text.Blaze.Html.Renderer.Text (renderHtml)
import Hledger.Data.Amount (nullamt)
import Hledger.Utils.Test
import Hledger.Write.Html.Attribute qualified as Attr
import Hledger.Write.Spreadsheet (Type(..), Style(..), Emphasis(..), Cell(..))
import Hledger.Write.Spreadsheet qualified as Spr
htmlAsText :: Html -> Text
htmlAsText :: Html -> Text
htmlAsText = LazyText -> Text
TL.toStrict (LazyText -> Text) -> (Html -> LazyText) -> Html -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Html -> LazyText
renderHtml
htmlAsLazyText :: Html -> TL.Text
htmlAsLazyText :: Html -> LazyText
htmlAsLazyText = Html -> LazyText
renderHtml
nl :: Html
nl :: Html
nl = Text -> Html
forall a. ToMarkup a => a -> Html
H.preEscapedToHtml (Text
"\n" :: Text)
styledTableHtml :: (Lines border) => [[Cell border Html]] -> Html
styledTableHtml :: forall border. Lines border => [[Cell border Html]] -> Html
styledTableHtml = Text -> [[Cell border Html]] -> Html
forall border. Lines border => Text -> [[Cell border Html]] -> Html
titledTableHtml Text
Text.empty
titledTableHtml :: (Lines border) => Text -> [[Cell border Html]] -> Html
titledTableHtml :: forall border. Lines border => Text -> [[Cell border Html]] -> Html
titledTableHtml Text
title [[Cell border Html]]
table = do
Html -> Html
H.style (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ Text -> Html
forall a. ToMarkup a => a -> Html
H.preEscapedToHtml Text
Attr.tableStylesheet
Html
nl
Html
H.link Html -> Attribute -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
A.rel AttributeValue
"stylesheet" Html -> Attribute -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
A.href AttributeValue
"hledger.css"
Html
nl
Bool -> Html -> Html
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text -> Bool
Text.null Text
title) (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ Text -> Html
formatTitle Text
title
Html -> Html
H.table (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ Html
nl Html -> Html -> Html
forall a. Semigroup a => a -> a -> a
<> ([Cell border Html] -> Html) -> [[Cell border Html]] -> Html
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ [Cell border Html] -> Html
forall border. Lines border => [Cell border Html] -> Html
formatRow [[Cell border Html]]
table
formatRow :: (Lines border) => [Cell border Html] -> Html
formatRow :: forall border. Lines border => [Cell border Html] -> Html
formatRow [Cell border Html]
row = Html -> Html
H.tr ((Cell border Html -> Html) -> [Cell border Html] -> Html
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ Cell border Html -> Html
forall border. Lines border => Cell border Html -> Html
formatCell [Cell border Html]
row) Html -> Html -> Html
forall a. Semigroup a => a -> a -> a
<> Html
nl
formatTitle :: Text -> Html
formatTitle :: Text -> Html
formatTitle Text
title = (Html -> Html
H.h3 (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
A.class_ AttributeValue
"report-title") (Text -> Html
forall a. ToMarkup a => a -> Html
toHtml Text
title) Html -> Html -> Html
forall a. Semigroup a => a -> a -> a
<> Html
nl
formatCell :: (Lines border) => Cell border Html -> Html
formatCell :: forall border. Lines border => Cell border Html -> Html
formatCell Cell border Html
cell =
let amountSpan :: Html -> Html
amountSpan = Html -> Html
H.span (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
A.class_ AttributeValue
"amount" in
let str :: Html
str =
case Cell border Html -> [Html]
forall border text. Cell border text -> [text]
cellParts Cell border Html
cell of
[] -> case Cell border Html -> Type
forall border text. Cell border text -> Type
cellType Cell border Html
cell of
TypeAmount Amount
_ -> Html -> Html
amountSpan (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ Cell border Html -> Html
forall border text. Cell border text -> text
cellContent Cell border Html
cell
Type
_ -> Cell border Html -> Html
forall border text. Cell border text -> text
cellContent Cell border Html
cell
[Html]
parts ->
[Html] -> Html
forall a. Monoid a => [a] -> a
mconcat ([Html] -> Html) -> [Html] -> Html
forall a b. (a -> b) -> a -> b
$ Html -> [Html] -> [Html]
forall a. a -> [a] -> [a]
intersperse (Text -> Html
forall a. ToMarkup a => a -> Html
toHtml (Text
", "::Text)) ([Html] -> [Html]) -> [Html] -> [Html]
forall a b. (a -> b) -> a -> b
$
(Html -> Html) -> [Html] -> [Html]
forall a b. (a -> b) -> [a] -> [b]
map Html -> Html
amountSpan [Html]
parts in
let content :: Html
content =
if Text -> Bool
Text.null (Text -> Bool) -> Text -> Bool
forall a b. (a -> b) -> a -> b
$ Cell border Html -> Text
forall border text. Cell border text -> Text
cellAnchor Cell border Html
cell
then Html
str
else ((Html -> Html) -> Attribute -> Html -> Html)
-> (Html -> Html) -> [Attribute] -> Html -> Html
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
(!) Html -> Html
H.a
(AttributeValue -> Attribute
A.href (Text -> AttributeValue
H.textValue (Text -> AttributeValue) -> Text -> AttributeValue
forall a b. (a -> b) -> a -> b
$ Cell border Html -> Text
forall border text. Cell border text -> Text
cellAnchor Cell border Html
cell) Attribute -> [Attribute] -> [Attribute]
forall a. a -> [a] -> [a]
:
[AttributeValue -> Attribute
A.title (Text -> AttributeValue
H.textValue (Text -> AttributeValue) -> Text -> AttributeValue
forall a b. (a -> b) -> a -> b
$ Cell border Html -> Text
forall border text. Cell border text -> Text
cellTitle Cell border Html
cell) | Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Text -> Bool
Text.null (Text -> Bool) -> Text -> Bool
forall a b. (a -> b) -> a -> b
$ Cell border Html -> Text
forall border text. Cell border text -> Text
cellTitle Cell border Html
cell])
Html
str in
let class_ :: [Attribute]
class_ =
([Text] -> Attribute) -> [[Text]] -> [Attribute]
forall a b. (a -> b) -> [a] -> [b]
map (AttributeValue -> Attribute
A.class_ (AttributeValue -> Attribute)
-> ([Text] -> AttributeValue) -> [Text] -> Attribute
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> AttributeValue
H.textValue (Text -> AttributeValue)
-> ([Text] -> Text) -> [Text] -> AttributeValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Text
Text.unwords) ([[Text]] -> [Attribute]) -> [[Text]] -> [Attribute]
forall a b. (a -> b) -> a -> b
$
([Text] -> Bool) -> [[Text]] -> [[Text]]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> ([Text] -> Bool) -> [Text] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null) ([[Text]] -> [[Text]]) -> [[Text]] -> [[Text]]
forall a b. (a -> b) -> a -> b
$
[(Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Text -> Bool) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Bool
Text.null) ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$
Class -> Text
Spr.textFromClass (Cell border Html -> Class
forall border text. Cell border text -> Class
cellClass Cell border Html
cell) Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
:
[Text
"date" | Cell border Html -> Type
forall border text. Cell border text -> Type
cellType Cell border Html
cell Type -> Type -> Bool
forall a. Eq a => a -> a -> Bool
== Type
TypeDate] [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++
Cell border Html -> [Text]
forall border text. Lines border => Cell border text -> [Text]
borderClasses Cell border Html
cell] in
let addSpan :: (AttributeValue -> a) -> a -> [a] -> [a]
addSpan AttributeValue -> a
spanAttr a
n [a]
attrs =
if a
na -> a -> Bool
forall a. Eq a => a -> a -> Bool
==a
1
then [a]
attrs
else AttributeValue -> a
spanAttr (String -> AttributeValue
H.stringValue (String -> AttributeValue) -> String -> AttributeValue
forall a b. (a -> b) -> a -> b
$ a -> String
forall a. Show a => a -> String
show a
n) a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
attrs in
let span_ :: (t -> f ()) -> [Attribute] -> t -> f ()
span_ t -> f ()
makeCell [Attribute]
attrs t
cont =
case Cell border Html -> Span
forall border text. Cell border text -> Span
Spr.cellSpan Cell border Html
cell of
Span
Spr.NoSpan -> ((t -> f ()) -> Attribute -> t -> f ())
-> (t -> f ()) -> [Attribute] -> t -> f ()
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl (t -> f ()) -> Attribute -> t -> f ()
forall h. Attributable h => h -> Attribute -> h
(!) t -> f ()
makeCell [Attribute]
attrs t
cont
Span
Spr.Covered -> () -> f ()
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
Spr.SpanHorizontal Int
n ->
((t -> f ()) -> Attribute -> t -> f ())
-> (t -> f ()) -> [Attribute] -> t -> f ()
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl (t -> f ()) -> Attribute -> t -> f ()
forall h. Attributable h => h -> Attribute -> h
(!) t -> f ()
makeCell ((AttributeValue -> Attribute) -> Int -> [Attribute] -> [Attribute]
forall {a} {a}.
(Eq a, Num a, Show a) =>
(AttributeValue -> a) -> a -> [a] -> [a]
addSpan AttributeValue -> Attribute
A.colspan Int
n [Attribute]
attrs) t
cont
Spr.SpanVertical Int
n ->
((t -> f ()) -> Attribute -> t -> f ())
-> (t -> f ()) -> [Attribute] -> t -> f ()
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl (t -> f ()) -> Attribute -> t -> f ()
forall h. Attributable h => h -> Attribute -> h
(!) t -> f ()
makeCell ((AttributeValue -> Attribute) -> Int -> [Attribute] -> [Attribute]
forall {a} {a}.
(Eq a, Num a, Show a) =>
(AttributeValue -> a) -> a -> [a] -> [a]
addSpan AttributeValue -> Attribute
A.rowspan Int
n [Attribute]
attrs) t
cont
in
case Cell border Html -> Style
forall border text. Cell border text -> Style
cellStyle Cell border Html
cell of
Style
Head -> (Html -> Html) -> [Attribute] -> Html -> Html
forall {t} {f :: * -> *}.
(Attributable (t -> f ()), Applicative f) =>
(t -> f ()) -> [Attribute] -> t -> f ()
span_ Html -> Html
H.th [Attribute]
class_ Html
content
Body Emphasis
emph ->
let align :: [Attribute]
align =
case Cell border Html -> Type
forall border text. Cell border text -> Type
cellType Cell border Html
cell of
Type
TypeString -> []
Type
TypeDate -> []
Type
_ -> [Tag -> AttributeValue -> Attribute
H.customAttribute Tag
"align" AttributeValue
"right"]
valign :: [Attribute]
valign =
case Cell border Html -> Span
forall border text. Cell border text -> Span
Spr.cellSpan Cell border Html
cell of
Spr.SpanVertical Int
n ->
if Int
nInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>Int
1
then [Tag -> AttributeValue -> Attribute
H.customAttribute Tag
"valign" AttributeValue
"top"]
else []
Span
_ -> []
withEmph :: Html -> Html
withEmph =
case Emphasis
emph of
Emphasis
Item -> Html -> Html
forall a. a -> a
id
Emphasis
Total -> Html -> Html
H.b
in (Html -> Html) -> [Attribute] -> Html -> Html
forall {t} {f :: * -> *}.
(Attributable (t -> f ()), Applicative f) =>
(t -> f ()) -> [Attribute] -> t -> f ()
span_ Html -> Html
H.td ([Attribute]
align[Attribute] -> [Attribute] -> [Attribute]
forall a. [a] -> [a] -> [a]
++[Attribute]
valign[Attribute] -> [Attribute] -> [Attribute]
forall a. [a] -> [a] -> [a]
++[Attribute]
class_) (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$
Html -> Html
withEmph Html
content
borderClasses :: Lines border => Cell border text -> [Text]
borderClasses :: forall border text. Lines border => Cell border text -> [Text]
borderClasses Cell border text
cell =
[ Text
"border-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
side Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
cls
| (Text
side, Border border -> border
access) <-
[ (Text
"left", Border border -> border
forall lines. Border lines -> lines
Spr.borderLeft)
, (Text
"right", Border border -> border
forall lines. Border lines -> lines
Spr.borderRight)
, (Text
"top", Border border -> border
forall lines. Border lines -> lines
Spr.borderTop)
, (Text
"bottom", Border border -> border
forall lines. Border lines -> lines
Spr.borderBottom)
]
, Just Text
cls <- [border -> Maybe Text
forall border. Lines border => border -> Maybe Text
borderClass (border -> Maybe Text) -> border -> Maybe Text
forall a b. (a -> b) -> a -> b
$ Border border -> border
access (Border border -> border) -> Border border -> border
forall a b. (a -> b) -> a -> b
$ Cell border text -> Border border
forall border text. Cell border text -> Border border
cellBorder Cell border text
cell]
]
class (Spr.Lines border) => Lines border where
borderClass :: border -> Maybe Text
instance Lines () where
borderClass :: () -> Maybe Text
borderClass () = Maybe Text
forall a. Maybe a
Nothing
instance Lines Spr.NumLines where
borderClass :: NumLines -> Maybe Text
borderClass NumLines
prop =
case NumLines
prop of
NumLines
Spr.NoLine -> Maybe Text
forall a. Maybe a
Nothing
NumLines
Spr.SingleLine -> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"single"
NumLines
Spr.DoubleLine -> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"double"
tests_Hledger_Write_Html :: TestTree
tests_Hledger_Write_Html = String -> [TestTree] -> TestTree
testGroup String
"Write.Html" [
String -> Assertion -> TestTree
testCase String
"formatCell" (Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$ do
let cell :: Cell NumLines Text -> Text
cell = Html -> Text
htmlAsText (Html -> Text)
-> (Cell NumLines Text -> Html) -> Cell NumLines Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Cell NumLines Html -> Html
forall border. Lines border => Cell border Html -> Html
formatCell (Cell NumLines Html -> Html)
-> (Cell NumLines Text -> Cell NumLines Html)
-> Cell NumLines Text
-> Html
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Html) -> Cell NumLines Text -> Cell NumLines Html
forall a b. (a -> b) -> Cell NumLines a -> Cell NumLines b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Html
forall a. ToMarkup a => a -> Html
toHtml
str :: Text -> Cell NumLines Text
str = Text -> Cell NumLines Text
forall border text. Lines border => text -> Cell border text
Spr.defaultCell :: Text -> Cell Spr.NumLines Text
Cell NumLines Text -> Text
cell (Text -> Cell NumLines Text
str Text
"a") Text -> Text -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Text
"<td>a</td>"
Cell NumLines Text -> Text
cell (Text -> Cell NumLines Text
str Text
"a<b>&\"c\"") Text -> Text -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Text
"<td>a<b>&"c"</td>"
Cell NumLines Text -> Text
cell (Text -> Cell NumLines Text
forall borders. Lines borders => Text -> Cell borders Text
Spr.headerCell Text
"h") Text -> Text -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Text
"<th>h</th>"
Cell NumLines Text -> Text
cell (Text -> Cell NumLines Text
str Text
"2026-01-01") {cellType = TypeDate} Text -> Text -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Text
"<td class=\"date\">2026-01-01</td>"
Cell NumLines Text -> Text
cell (Text -> Cell NumLines Text
str Text
"$1") {cellType = TypeAmount nullamt, cellClass = Spr.Class "amount"}
Text -> Text -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Text
"<td align=\"right\" class=\"amount\"><span class=\"amount\">$1</span></td>"
Cell NumLines Text -> Text
cell (Text -> Cell NumLines Text
str Text
"$1, 2 €") {cellType = TypeMixedAmount, cellParts = ["$1", "2 €"]}
Text -> Text -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Text
"<td align=\"right\"><span class=\"amount\">$1</span>, <span class=\"amount\">2 €</span></td>"
Cell NumLines Text -> Text
cell (Text -> Cell NumLines Text
str Text
"a") {cellAnchor = "register?q=a&b"} Text -> Text -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Text
"<td><a href=\"register?q=a&b\">a</a></td>"
Cell NumLines Text -> Text
cell (Text -> Cell NumLines Text
str Text
"a") {cellAnchor = "register?q=a", cellTitle = "Show \"a\""}
Text -> Text -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Text
"<td><a href=\"register?q=a\" title=\"Show "a"\">a</a></td>"
Cell NumLines Text -> Text
cell (Text -> Cell NumLines Text
str Text
"a") {cellTitle = "t"} Text -> Text -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Text
"<td>a</td>"
Cell NumLines Text -> Text
cell (Text -> Cell NumLines Text
str Text
"Total:") {cellStyle = Body Total, cellBorder = Spr.noBorder {Spr.borderTop = Spr.DoubleLine}}
Text -> Text -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Text
"<td class=\"border-top-double\"><b>Total:</b></td>"
Cell NumLines Text -> Text
cell (Text -> Cell NumLines Text
forall borders. Lines borders => Text -> Cell borders Text
Spr.headerCell Text
"h" :: Cell Spr.NumLines Text) {cellClass = Spr.Class "account", cellBorder = Spr.noBorder {Spr.borderBottom = Spr.SingleLine}}
Text -> Text -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Text
"<th class=\"account border-bottom-single\">h</th>"
Cell NumLines Text -> Text
cell (Text -> Cell NumLines Text
str Text
"a") {cellSpan = Spr.SpanHorizontal 2} Text -> Text -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Text
"<td colspan=\"2\">a</td>"
Cell NumLines Text -> Text
cell (Text -> Cell NumLines Text
str Text
"a") {cellSpan = Spr.SpanHorizontal 1} Text -> Text -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Text
"<td>a</td>"
Cell NumLines Text -> Text
cell (Text -> Cell NumLines Text
str Text
"a") {cellSpan = Spr.SpanVertical 2} Text -> Text -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Text
"<td rowspan=\"2\" valign=\"top\">a</td>"
Cell NumLines Text -> Text
cell (Text -> Cell NumLines Text
str Text
"a") {cellSpan = Spr.Covered} Text -> Text -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Text
""
,String -> Assertion -> TestTree
testCase String
"formatRow" (Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$
Html -> Text
htmlAsText ([Cell () Html] -> Html
forall border. Lines border => [Cell border Html] -> Html
formatRow ([Cell () Html] -> Html) -> [Cell () Html] -> Html
forall a b. (a -> b) -> a -> b
$ (Cell () Text -> Cell () Html) -> [Cell () Text] -> [Cell () Html]
forall a b. (a -> b) -> [a] -> [b]
map ((Text -> Html) -> Cell () Text -> Cell () Html
forall a b. (a -> b) -> Cell () a -> Cell () b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Html
forall a. ToMarkup a => a -> Html
toHtml) [Text -> Cell () Text
forall border text. Lines border => text -> Cell border text
Spr.defaultCell Text
"a", Text -> Cell () Text
forall border text. Lines border => text -> Cell border text
Spr.defaultCell Text
"b" :: Cell () Text])
Text -> Text -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Text
"<tr><td>a</td><td>b</td></tr>\n"
,String -> Assertion -> TestTree
testCase String
"titledTableHtml" (Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$ do
let html :: Text
html = Html -> Text
htmlAsText (Html -> Text) -> Html -> Text
forall a b. (a -> b) -> a -> b
$ Text -> [[Cell () Html]] -> Html
forall border. Lines border => Text -> [[Cell border Html]] -> Html
titledTableHtml Text
"T & U" [(Cell () Text -> Cell () Html) -> [Cell () Text] -> [Cell () Html]
forall a b. (a -> b) -> [a] -> [b]
map ((Text -> Html) -> Cell () Text -> Cell () Html
forall a b. (a -> b) -> Cell () a -> Cell () b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Html
forall a. ToMarkup a => a -> Html
toHtml) [Text -> Cell () Text
forall borders. Lines borders => Text -> Cell borders Text
Spr.headerCell Text
"h" :: Cell () Text]]
Text -> Text -> Bool
Text.isPrefixOf Text
"<style>\ntable {" Text
html Bool -> Bool -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Bool
True
Text -> Text -> Bool
Text.isSuffixOf Text
"</style>\n<link rel=\"stylesheet\" href=\"hledger.css\">\n<h3 class=\"report-title\">T & U</h3>\n<table>\n<tr><th>h</th></tr>\n</table>" Text
html Bool -> Bool -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Bool
True
]