CleanX/ext/html
The html extension for CleanX extends Clean syntax to embed HTML notation in Clean codes.
Sample code
This is the sample code.
vTitles :: ![TitleInfo] -> HtmlData
vTitles tis = body $ HtmlData $ map (\{ti_title} = title ti_title) tis
where
body data =
__HTMLSTART__
<div id="sidebar">
<% data %>
</div>
__HTMLEND__
title t = let urlTitle = mkUrlTitle t in
__HTMLSTART__
<a href="<% ROOT %>view/<% urlTitle %>"><% HtmlText t %></a><br />
__HTMLEND__
It will be converted into the following Clean code.
vTitles :: ![TitleInfo] -> HtmlData
vTitles tis = body $ HtmlData $ map (\{ti_title} = title ti_title) tis
where
body data =
(HtmlData
[HtmlRaw "<div id=\"sidebar\">", HtmlRaw newline
, data , HtmlRaw newline
,HtmlRaw "</div>", HtmlRaw newline
])
title t = let urlTitle = mkUrlTitle t in
(HtmlData
[HtmlRaw "<a href=\"", ROOT , HtmlRaw "view/", urlTitle , HtmlRaw "\">", HtmlText t , HtmlRaw "</a><br />", HtmlRaw newline
])
Conversion rule
The embedded HTML notation begins with '__HTMLSTART__' and ends with '__HTMLEND__.' The code between these lines should be indented at the position where '__HTMLSTART__' begins.
The HTML codes are interpreted as HtmlData data type defined in OptHtml module in OptEnv library.
If some part of the embedded HTML code is surrounded with '<%' and '%>' or '<?' and '?>' then it will be interpreted as it is a Clean code. The type of the part should be of HtmlData data type.
Requirement
OptHtml module must be imported if the module uses html extension.
