-
Notifications
You must be signed in to change notification settings - Fork 0
CHT Syntax
The input language of the CHT engine has minimalistic syntax designed to preserve the usual structure and flow of the HTML. The entire input sequence (a .cht
file) consists of template definitions, each template definition may contain a mix of HTML and CHT elements with appropriate text content. The text content as well as HTML attribute values may also contain substitution expressions used to embed computed values into the HTML output.
<?
[ Prefix.
] TagName [ Argument ] [ KeywordArgument … ]?>
The CHT tags are enclosed in <?
and ?>
brackets, reminiscent of the XML processing instructions. Simple elements have no content; structured elements may have content (HTML, CHT and/or text), optionally separated into sections:
<?
[ Prefix.
] TagName [ Argument ] [ KeywordArgument … ]?>
div{margin-left:1em}. Content
(. [
((.<?
SectionName [ Argument ]?>
(((. Content
((. …
(. ]
<?
/
TagName?>
CHT elements may have one positional argument which is either a simple text string that does not contain spaces or characters =
, <
, >
or a quoted string (with either double or single quotes). Note that characters <
, >
and &
are allowed in quoted arguments within CHT tags but not within HTML tags where standard rules apply. Some CHT elements may have keyword arguments that follow the standard HTML syntax, except that characters <
, >
and &
are allowed within their values. In most cases, the argument values are Q\+ expressions (see the section on Q\+ below for the details).
Note that sections may have positional arguments as well, but they don’t have the equivalent of closing tags: a section ends where another section begins or where the enclosing structured element ends. Content between the opening tag and the first section syntactically belongs to a “default” or “unnamed” section; this may or may not be valid semantically depending on the nature of the structured element.
Aside from the tags used in template definitions (<?template?>
and <?section?>
CHT provides a few built-in elements and allows the user to define both simple and structured elements of his own. At the moment, user-defined structured elements have one limitation: their sections cannot repeat (i.e. cannot be used more than once within the same element).
{panel}
{html}
</TT> <I>Q+Expression</I> <TT>
{html}
{panel}
The substitution expressions use the Q\+ syntax described below in a separate section. Substitution expressions are processed within text content and within HTML argument values but not within CHT tags, including argument values (which tend to be Q\+ expressions themselves anyway). All substitution expressions are evaluated in singleton mode (i.e. they are not generators).
{panel}
<?
template
Name ?>
{html}
{html}
<?
/template
?>
{panel}
References to simple user-defined elements, i.e. <?
Name \Argument \] ?>
are replaced with expansions of their content based on the passed in argument value. If the argument is omitted, the template is evaluated against current input determined from the context where its reference was encountered.
{panel}
<?
template
Name ?>
{html}
Content
[
<? section [SectionName] ?>
<? /section ?>
Content
…
{html}
<?
/template
?>
{panel}
References to structured user-defined elements are replaced with expansions of the template-level content. Section content supplied at the point of reference is substituted in place of section definitions unless a particular section is omitted; DefaultSectionContent is used in its place then. Content between the opening tag of the template reference and the first section tag is substituted in place of the default/unnamed section (which cannot have default content). Arguments may be passed to the template itself (which applies to the template-level content as well as to the default/unnamed section, if present) and to any of the sections.
{panel}
<?
if
\IfArgument_\] ?>
{html}
IfContent
[
<? elseif ElseIfArgument ?>
<DIV mcestyle=“margin-left:1em” style=“margin-left: 1em;”>
ElseIfContent
]
{html}
{html}
<? else ?>
ElseContent
{html}
<?
/if
?>
{panel}
Expands to IfContent if IfArgument evaluates to a true
\-like value or to ElseIfContent if the corresponding ElseIfArgument does; otherwise expands to ElseContent. All arguments are Q\+ expressions evaluated in a singleton context (i.e. they are not generators).
{panel}
<?
foreach
\Generator_\] ?>
{html}
<DIV mcestyle=“margin-left:1em” style=“margin-left: 1em;”>Content
{html}
<?
/foreach
?>
{panel}
Expands to a concatenation of Content evaluated for every value from Generator. The Generator is a Q\+ expression (query) evaluated in an iterative mode; the <?foreach?>
element serves as a sink for the Generator.
{panel}
<?
group
\Generator_\] \{ key=
{_}KeyList \| count=
{_}Count_ \} ?>
{html}
{html}
<?
/group
?>
{panel}
A counterpart to the group
tag in JXL: expands to a concatenation of Content evaluated for every group formed by splitting the sequence generated by Generator. The splitting can be done either based on KeyList, which is a comma-separated list of Q\+ expressions evaluated for every value in sequence or into groups of equal size based on Count.
The content of the <?group?>
element in CHT is logically equivalent to the body
argument of the group()
in JXL: its current input is set to the current subsequence formed according to the grouping rules. To iterate over current subsequence, use a nested <?foreach?>
or another <?group?>
.