Hyogen Blocks
hyogen.md logic lives inside HTML comments so Markdown previews stay clean.
Standard form
<!--
@hg
const greeting = "hello"
@endhg
-->
Variants that work equally:
<!--@hg
const x = 1
@endhg-->
<!--@hg /* one-line block */ @endhg-->
Shorthand form
@@ … @@ is equivalent to @hg … @endhg:
<!--@@
include ./partials/header.md
@@-->
<!--@@ include ./partials/footer.md @@-->
Use /* */ for inline comments in one-line blocks (not //, which ends at newline).
echo
echo <expr> writes the expression result into the document by replacing the enclosing @hg / @@ comment.
<!--
@hg
const greet = "Hello world!"
echo greet
@endhg
-->
Output:
Hello world!
You can declare in one block and echo in a shorthand block:
<!--@hg
const greet = "Hello world!"
@endhg-->
<!--@@ echo greet @@-->
Multiple echo statements (including inside for / do…while) concatenate with no separator. null / undefined become an empty string (same as {{ }}).
What goes inside
| Category | Examples |
|---|---|
| Declarations | const, let, reassignment |
| Output | echo <expr> — replace the block with the evaluated string |
| Includes | include, component … as, extend |
| Control flow | if / else / each (structural — wrap Markdown body) |
| Helpers | toc / toc(N) — see TOC helper |
| Loops | for (…), do … while |
See Declarations, Control flow, and TOC helper.
Code fences
Hyogen blocks inside fenced code are not executed:
```html
<!-- @hg const x = 1 @endhg -->
```
${expr} inside fences is expanded (same expression rules as @hg template literals). Outside fences, ${…} stays literal. Escape with \${. See Expressions.
```markdown
# ${title}
```
Mustache {{ }} still expands even inside fences.
Output preservation
By default, hyogen comment blocks are removed from output. Set preserveHgComments: true to keep them for debugging.
JS comments inside blocks
<!--
@hg
// line comment
/* block comment */
@endhg
-->