Skip to content

Commit f383f3d

Browse files
committed
initial table description render logic
1 parent 25c0f70 commit f383f3d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Distribution/Server/Pages/Package/HaddockHtml.hs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ htmlMarkup modResolv = Markup {
3434
markupMathDisplay = \mathjax -> toHtml ("\\[" ++ mathjax ++ "\\]"),
3535
markupProperty = pre . toHtml,
3636
markupExample = examplesToHtml,
37-
markupHeader = \(Header l t) -> makeHeader l t
37+
markupHeader = \(Header l t) -> makeHeader l t,
38+
markupTable = \(Table h r) -> makeTable h r
3839
}
3940
where
4041
makeHeader :: Int -> Html -> Html
@@ -59,6 +60,24 @@ htmlMarkup modResolv = Markup {
5960
let lnk = anchor ! [href modUrl] << s
6061
pure (thespan ! [theclass "module"] << lnk)
6162

63+
makeTable :: [TableRow Html] -> [TableRow Html] -> Html
64+
makeTable hs bs = table (concatHtml (hs' ++ bs'))
65+
where
66+
hs' | null hs = []
67+
| otherwise = [thead (concatHtml (map (makeTableRow th) hs))]
68+
69+
bs' = [tbody (concatHtml (map (makeTableRow td) bs))]
70+
71+
makeTableRow :: (Html -> Html) -> TableRow Html -> Html
72+
makeTableRow thr (TableRow cs) = tr (concatHtml (map (makeTableCell thr) cs))
73+
74+
makeTableCell :: (Html -> Html) -> TableCell Html -> Html
75+
makeTableCell thr (TableCell i j c) = thr c ! (i' ++ j')
76+
where
77+
i' = if i == 1 then [] else [ colspan i ]
78+
j' = if j == 1 then [] else [ rowspan j ]
79+
80+
6281
namedAnchor :: String -> Html -> Html
6382
namedAnchor n = anchor ! [name (escapeStr n)]
6483

0 commit comments

Comments
 (0)