Star 历史趋势
数据来源: GitHub API · 生成自 Stargazers.cn
README.md

Knap

Knap is a simple template language that turns data into Markdown using variables, filters, and logic. It powers templating in Obsidian Web Clipper and Obsidian Importer.

Documentation · Playground

Knap parses templates into an AST and interprets them without eval or arbitrary JavaScript execution. Applications control the data and integrations available to templates.

Install

npm install knap

Node.js 20 or later is required for the CLI.

CLI

Render a template with JSON data:

npx knap render template.md --data data.json --output note.md

Knap also supports inline templates, validation, batch rendering, CSV input, and offline language help. See the CLI guide.

Library

import { createEngine, standardFilters } from 'knap';

const engine = createEngine({ filters: standardFilters });

const markdown = await engine.renderOrThrow(
	'# {{ title | trim }}\n\n{{ tags | list }}',
	{
		variables: {
			title: '  An imported note  ',
			tags: ['reference', 'reading'],
		},
	},
);

See the API guide for rendering, validation, custom filters, asynchronous variables, HTML filters, and execution limits.

Syntax highlighting

Knap syntax highlighting is available for .knap and .knap.md templates:

  • VS Code and Cursor: Download knap.vsix from the latest release, then choose Extensions: Install from VSIX from the command palette.
  • Sublime Text 4: Download Knap.sublime-package from the latest release and place it in Sublime Text's Installed Packages folder.
  • Prism: Run npm install knap prismjs, then import the adapter from knap/prism.
  • CodeMirror 6: Run npm install knap @codemirror/language, then import the adapter from knap/codemirror.
  • highlight.js: Run npm install knap highlight.js, then import the adapter from knap/highlightjs.

See the syntax highlighting guide for setup examples, CodeMirror 5 support, and editor-specific details.

Documentation

Development

pnpm install
pnpm check

The portable rendering fixtures make selected documentation examples and regression expectations reusable by implementations in other languages.

Knap is available under the MIT License.

关于 About

A simple template language that turns data into Markdown.
cliknaplanguagemarkdownobsidiantemplatetemplate-enginetemplate-languagetemplating

语言 Languages

TypeScript83.9%
Astro7.8%
SCSS5.1%
JavaScript3.2%

提交活跃度 Commit Activity

代码提交热力图
过去 52 周的开发活跃度
92
Total Commits
峰值: 65次/周
Less
More

核心贡献者 Contributors