sercrod

*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:

Inside a *literal block:

*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:

Behavior

Core rules:

Source of the text:

In both modes:

“Keep Sercrod as text” use case

The primary design goal of *literal is to display Sercrod markup itself:

Example:

<serc-rod id="docs">
  <p>Description</p>
  <pre *literal>
%user.name% ordered %item.name% at %item.price%.
  </pre>
</serc-rod>

Result:

Attribute vs innerHTML source

Two common patterns:

  1. Boolean-style *literal (innerHTML source):

    • No value, or an empty value:

      <pre *literal>
```
  1. Value-style *literal (attribute source):

    • Value is treated as a plain string, not as an expression:

      <p *literal="*if=&quot;isVisible&quot;">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:

Evaluation timing

*literal is handled early in the rendering pipeline:

Because of this:

Execution model

Conceptually, for an element with *literal:

  1. Sercrod detects *literal / n-literal on the element.

  2. It reads:

    • attr = element.getAttribute("*literal") || element.getAttribute("n-literal").
  3. It determines the text:

    • If attr is a non-empty string, text = String(attr).
    • Otherwise, text = element.innerHTML (as originally written in the template).
  4. It clears or replaces the element’s children with a single text content node based on text.

  5. In the cleanup phase:

    • *literal and n-literal attributes 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:

You can still use scope and data around the literal element:

Parent access

Because Sercrod does not descend into *literal blocks:

Use with conditionals and loops

The rule becomes very straightforward once you think of *literal as “keep everything inside as plain text”:

For this reason:

Instead, use an outer element for logic:

```

%snippet.body%

```

Best practices

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>

Notes