*literal
Summary
*literal is used when you want to keep Sercrod-style markup (or any template-like text) exactly as written, without Sercrod expanding or interpreting it. Typical use cases include:
- Showing Sercrod examples in documentation.
- Emitting
%placeholders%or*directivesas plain text for another system to process later.
Inside a *literal block:
- Sercrod does not evaluate
%...%interpolation. - Sercrod does not treat
*if,*for,@click, or any other directives as behavior. - Only the
*literal/n-literalattribute itself is removed in the final output; the content is kept as plain text.
*literal has an alias n-literal.
Basic example
Display Sercrod markup as-is, so that it is shown as code instead of being executed:
<serc-rod id="docs">
<h2>Counter example</h2>
<pre *literal>
<serc-rod data='{"count":0}'>
<button @click="count++">+</button>
<span *print="count"></span>
</serc-rod>
</pre>
</serc-rod>
Behavior:
- Sercrod does not interpret the inner
<serc-rod>,@click, or*printin the<pre>block. - The final DOM contains a
<pre>whose text content is the Sercrod snippet, exactly as written. - The
*literalattribute itself is removed by the cleanup phase, so end users will not see it.
Behavior
Core rules:
- If an element has
*literalorn-literal, Sercrod treats the element’s content as plain text. - Directives and interpolation markers inside that element are not executed; they are preserved as characters.
- The host element itself is kept (for example
<pre>,<p>,<div>), but*literal/n-literalis removed from the output DOM when directive cleanup is enabled.
Source of the text:
-
Sercrod first looks at the attribute value:
- If
*literal/n-literalhas a non-empty value, that string is used as the text. - Example:
<div *literal="*if="cond"">...</div>outputs*if="cond"as text.
- If
-
If the attribute value is empty or not specified:
- Sercrod uses the original
innerHTMLas the text. - Example:
<pre *literal>...inner markup...</pre>outputs the inner markup exactly as characters.
- Sercrod uses the original
In both modes:
- The chosen text is emitted without Sercrod expression evaluation.
- Characters like
<,>,%,", and*are not treated specially by Sercrod.
“Keep Sercrod as text” use case
The primary design goal of *literal is to display Sercrod markup itself:
- You can write Sercrod templates inside
*literalblocks to show them as examples. - You can keep
%user.name%or%item.price%as placeholders, ready for a different rendering engine.
Example:
<serc-rod id="docs">
<p>Description</p>
<pre *literal>
%user.name% ordered %item.name% at %item.price%.
</pre>
</serc-rod>
Result:
- Sercrod does not try to evaluate
%user.name%or%item.price%. - The placeholders appear exactly as written in the rendered page.
- Only
*literalis removed from the markup; the rest is preserved as plain text inside<pre>.
Attribute vs innerHTML source
Two common patterns:
-
Boolean-style
*literal(innerHTML source):-
No value, or an empty value:
<pre *literal>
-
- Sercrod uses the inner HTML as the text source.
- The element becomes a
<pre>with that snippet as its text content. - The
*literalattribute is removed.
-
Value-style
*literal(attribute source):-
Value is treated as a plain string, not as an expression:
<p *literal="*if="isVisible"">Will show *if="isVisible"</p> -
The visible text is
*if="isVisible". -
The inner content (
Will show ...) is ignored in this mode. -
Sercrod does not try to evaluate
isVisible; it just prints the attribute value as text.
-
Important:
- The
*literalvalue is never interpreted as a Sercrod expression. - If you need data-driven text based on scope variables, use
*printor bindings instead.
Evaluation timing
*literal is handled early in the rendering pipeline:
-
In the main render flow, Sercrod:
- Handles static/dynamic flags.
- Then checks for
*literal/n-literal.
-
If
*literalorn-literalis present:- Sercrod decides the text to output (from the attribute or innerHTML).
- Sets the element’s text content or appends a text node (depending on the internal path).
- Skips further processing for that node.
Because of this:
- Any other directive on the same element as
*literalis effectively ignored by the runtime. - Children of that element are not visited by Sercrod’s directive engine.
- The element becomes a “literal island” with no Sercrod behavior inside it.
Execution model
Conceptually, for an element with *literal:
-
Sercrod detects
*literal/n-literalon the element. -
It reads:
attr = element.getAttribute("*literal") || element.getAttribute("n-literal").
-
It determines the text:
- If
attris a non-empty string,text = String(attr). - Otherwise,
text = element.innerHTML(as originally written in the template).
- If
-
It clears or replaces the element’s children with a single text content node based on
text. -
In the cleanup phase:
*literalandn-literalattributes are removed from the output DOM.- The element itself remains in the DOM (for example
<pre>,<p>).
At no point does Sercrod interpret or expand directives, events, or %...% placeholders within that element.
Variable creation and scope layering
*literal does not create or modify any variables:
- No new local variables are introduced.
$data,$root,$parent, and other scope entries are unaffected.- There is no per-child scope inside a
*literalblock, because Sercrod does not descend into the element to render children.
You can still use scope and data around the literal element:
- Ancestors and siblings behave as usual.
- Use outer
*if,*for, or bindings on surrounding elements to control when and where the literal block appears.
Parent access
Because Sercrod does not descend into *literal blocks:
- There is no Nested Sercrod scope inside that element.
- Inner markup (even if it looks like Sercrod) is just text; it cannot access
$parentor other scope variables. - Parent scopes are only relevant for deciding whether the element itself is rendered at all (through directives on parent elements).
Use with conditionals and loops
The rule becomes very straightforward once you think of *literal as “keep everything inside as plain text”:
-
*literaland other directives on the same element conflict conceptually:*ifor*foron the same element would suggest “execute logic”.*literalsays “do not execute anything inside; keep it as text”.
-
Implementation-wise,
*literalwins:- Because
*literalis handled early, Sercrod does not get to the other directives on that element. - So
*if,*for,@click, or any other directives on the same element effectively do nothing.
- Because
For this reason:
- Do not combine
*literalwith other*/n-/@directives on the same element.
Instead, use an outer element for logic:
-
Conditional display of a literal block:
<section *if="showExample"> <pre *literal>
-
*ifcontrols whether the whole example is shown. -
*literalensures the inner Sercrod snippet is preserved as text. -
Looping over literal snippets:
<ul *for="snippet of snippets"> <li> <pre *literal>
%snippet.body%
```*forrepeats<li>for eachsnippet.- Each
<pre *literal>contains a literal template for that snippet.
Best practices
-
Use
*literalwhenever you want Sercrod markup or%placeholders%to appear as text:- Documentation for Sercrod itself.
- Email or template previews that use
%%-style placeholders. - Raw Markdown or other template languages that should not be touched by Sercrod.
-
Keep
*literalalone on its element:- Do not add
*if,*for,*each,@event, or other directives to the same element. - Place conditionals and loops on a parent element, and use
*literalpurely to protect the inner content.
- Do not add
-
Prefer innerHTML for larger literal blocks:
- For large code samples or long Markdown sections, use the boolean-style
*literaland write the content in the body. - Use attribute-style
*literal="...text..."for short strings that must remain literal.
- For large code samples or long Markdown sections, use the boolean-style
-
Combine with
*remwhen you want no output:*literalis for “keep literal content as text”.*remis for “keep in the template only; remove from rendered output”.
Additional examples
Literal Sercrod block with outer logic:
<serc-rod id="examples" data='{"show":"counter"}'>
<section *if="show === 'counter'">
<h3>Counter example</h3>
<pre *literal>
<serc-rod data='{"count":0}'>
<button @click="count++">+</button>
<span *print="count"></span>
</serc-rod>
</pre>
</section>
</serc-rod>
Literal placeholders for another system:
<serc-rod id="mailer">
<p *literal>
%USER_NAME%, thank you for signing up.
Your order number is %ORDER_ID%.
</p>
</serc-rod>
- Sercrod does not expand
%USER_NAME%or%ORDER_ID%. - The string is emitted exactly as written, ready for another mail-merge system.
Notes
*literalandn-literalare aliases; choose one style per project for consistency.*literalis evaluated early and prevents Sercrod from interpreting anything inside that element.- The main purpose is to keep Sercrod-style markup (or other templates) as text, while removing only the
*literaldirective itself from the final HTML. - Combining
*literalwith other directives on the same element is not supported in practice, because*literalshort-circuits those directives; use parent elements for conditionals and loops instead.