Skip to content

crimx/agentic-markdown

Repository files navigation

agentic-markdown

Build Status npm-version Coverage Status minified-size

A tiny Markdown-first template engine for variables and conditional content.

Directives live in HTML comments to avoid colliding with Markdown content or other template syntaxes.

Install

npm add agentic-markdown

Usage

import { render } from "agentic-markdown";

const markdown = `Common content.

Project: <!-- agentic:var projectName -->

<!-- agentic:if agent=codex -->
Codex-only content.
<!-- agentic:endif -->

<!-- agentic:if agent=claude|gemini -->
Claude and Gemini content.
<!-- agentic:endif -->
`;

const output = render(markdown, {
  agent: "codex",
  projectName: "agentic-markdown",
});

output:

Common content.

Project: agentic-markdown

Codex-only content.

Syntax

Use HTML comment directives to mark conditional Markdown spans:

<!-- agentic:if agent=codex -->
Codex-only content.
<!-- agentic:elseif agent=claude -->
Claude-only content.
<!-- agentic:else -->
Other-agent content.
<!-- agentic:endif -->

They may also appear inline:

Use <!-- agentic:if agent=codex -->Codex<!-- agentic:endif --> instructions.

The agentic:if and agentic:elseif values are either variable=value conditions or presence/non-empty checks. Use | to match any of multiple values. Matching is case-sensitive. agentic:else accepts no condition and is kept only when no previous branch in the chain matched.

render(markdown, { agent: "codex" });

A variable=value block is kept when the configured variable matches one of the expected values. Missing variables are treated as non-matches instead of errors.

Omit = to keep a block when the configured variable has a non-empty value. Missing or empty variables are also treated as non-matches:

<!-- agentic:if projectName -->
Project-specific content.
<!-- agentic:endif -->

Use agentic:var comments to replace variables. They may appear inline or on their own line:

Project: <!-- agentic:var projectName -->
render(markdown, {
  projectName: "agentic-markdown",
});

agentic:var requires the variable to be configured. Missing variables throw an error.

When condition comments are on their own line, the whole directive line is removed. Inline condition comments only remove the comment itself, or the excluded span when the condition does not match. Nested condition blocks are not supported; malformed blocks throw an error.

About

A tiny Markdown-first template engine for variables and conditional content.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors