hyogen.md

0.14.0

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

CategoryExamples
Declarationsconst, let, reassignment
Outputecho <expr> — replace the block with the evaluated string
Includesinclude, component … as, extend
Control flowif / else / each (structural — wrap Markdown body)
Helperstoc / toc(N) — see TOC helper
Loopsfor (…), 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 &#123;&#123; &#125;&#125; 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
-->