public final class HtmlRewritePass extends CompilerFilePass
kind="html" or kind="attributes" to contain
HtmlOpenTagNode, HtmlCloseTagNode, HtmlAttributeNode, and HtmlAttributeValueNode.
The strategy is to parse the raw text nodes for html tokens and then trigger AST rewriting based on what we find.
An obvious question upon reading this should be "Why isn't this implemented in the grammar?" the answer is that soy has some language features that interfere with writing such a grammar.
{nil}, {sp}, {\n}
cause difficulties when writing grammar productions for html elements. This would be
manageable by preventing the use of these commands within html tags (though some of them
such as {sp} are popular so there are some compatibility concerns)
{literal}...{/literal} command. such commands often contain html
tags so within the grammar we would need to start writing grammar production which match
the contents of literal blocks. This is possible but would require duplicating all the
lexical states for literals. (Also we would need to deal with tags split across literal
blocks e.g. {/literal}).
- Transitioning between lexical states after seeing a
<script> tag or after parsing a
kind="html" attributes is complex (And 'semantic lexical transitions' are not
recommended).
On the other hand by implementing this here, a lot of these issues go away since all the text
has already been processed. Of course this doesn't mean it is easy since we need to implement our
own parser and state tracking system that is normally handled by the javacc grammar.
This class tries to be faithful to the Html syntax standard. Though we do not
attempt to implement the contextual element model, and matching tags is handled by a different
pass, the StrictHtmlValidationPass.
| Constructor and Description |
|---|
HtmlRewritePass(ErrorReporter errorReporter) |
| Modifier and Type | Method and Description |
|---|---|
void |
run(SoyFileNode file,
IdGenerator nodeIdGen) |
name, toStringpublic HtmlRewritePass(ErrorReporter errorReporter)
errorReporter - The error reporterpublic void run(SoyFileNode file, IdGenerator nodeIdGen)
run in class CompilerFilePass