wpart_erlsyntax
Overview
wpart_erlsyntax component is responsible for highlighting the Erlang code on the page. The application provides a single module: wpart_erlsyntax that is responsible for scanning the text and surrounding the content with the proper HTML tags.
Configuration
No configuration parameters are needed. During the install phase application copies its example CSS file into docroot directory (it is deleted during uninstall process).
Usage
In order to highlight some Erlang code we must use the following tags:
<wpart:erlsyntax type="style" path="Path" /> - returns the link to the CSS file. Note that the proper dispatcher rule must be entered into the dispatch.conf file. When path attribute is not provided, the default one (/erlsyntax.css) is used
<wpart:erlsyntax legend="Legend">Erlang Code</wpart:erlsyntax> - highlights the Erlang code surrounded by the tag and displays the proper Legend (this attribute is optional - no legend will be displayed unless it is specified)
Each element of the code will be surrounded with a proper container with the class attribute set:
each line will be surrounded with div class="line"
each function name will be surrounded with span class="function"
each string will be surrounded with span class="string"
each record will be surrounded with span class="record"
each variable will be surrounded with span class="variable"
each keyword will be surrounded with span class="keyword"
each preprocessor directive will be surrounded with span class="directive"
each comment will be surrounded with span class="comment"
each character (e.g. $a) will be surrounded with span class="character"
each macro will be surrounded with span class="macro"
You can define your own CSS outlook for each of the element type (color, font style, etc.)
Example
The following code pasted in the template:
<html>
<head>
<title>wpart_erlsyntax example</title>
<wpart:erlsyntax type="style" path="/erlsyntax_example.css" />
</head>
<body>
<h1>This is an example: </h1>
<wpart:erlsyntax legend="Example of the wpart_erlsyntax">
handle_call(E) ->
case wpart:has_attribute("attribute::type", E) of
"style" ->
Path = wpart:has_attribute("attribute::path", "/erlsyntax.css", E),
#xmlText{value=?CSS_HEADER(Path),
type=cdata};
false ->
Legend = case wpart:has_attribute("attribute::legend", E) of
false ->
"";
Desc ->
?LEGEND(Desc)
end,
Content = lists:foldl(fun xml_content_fold/2, [], E#xmlElement.content),
#xmlText{value=highlight_syntax(Content, Legend),
type=cdata};
_ ->
#xmlText{value="Bad formatted wpart:erlsyntax tag!",
type=cdata}
end.
</wpart:erlsyntax>
</body>
</html>will look in our browser in this way:
