Community生產力與協作github.com

kepano/knap

使用 Knap CLI 從模板與結構化資料渲染 Markdown。當使用者要求套用 Knap 模板、將 JSON 或 CSV 資料轉換為筆記、批次生成 Markdown 檔案,或將 Defuddle 輸出格式化為筆記時使用。

knap 是什麼?

Knap 是一款 CLI 工具,專門用於透過變數、篩選器與邏輯標籤來渲染 Markdown 模板。它能讓開發者將 JSON、CSV 等結構化資料與模板結合,批次產出格式化一致的 Markdown 文件,大幅簡化筆記生成、報告撰寫或資料轉換流程。支援 Node.js 20 以上環境,可透過 npm 全域安裝或使用 npx 直接執行。Knap 提供多種指令與離線參考文件,方便查閱語法與篩選器用法。其核心功能包含單一模板渲染、模板語法驗證、與 Defuddle 整合的網頁擷取管線,以及可針對 CSV、JSON 陣列或資料夾批次生成檔案的批次處理模式。透過 `--set` 可在渲染時覆蓋變數,輸出可導向 stdout 或直接寫入檔案。這套工具非常適合知識管理、自動化筆記生成、與結構化資料驅動的文件建立情境。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/kepano/obsidian-skills/tree/main/skills/knap

Installed? Explore more 生產力與協作 skills: steipete/gemini, steipete/gh-issues, steipete/skill-creator · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

knap 是做什麼的?

使用 Knap CLI 以變數、篩選器與邏輯渲染 Markdown 模板。

若未安裝:npm install -g knap(需要 Node.js 20 或更新版本)。亦可使用 npx knap。

執行 knap --help 查看可用指令與選項。透過 CLI 的離線參考來探索語言:

knap help syntax
knap help filters
knap help filter date
knap help tags
knap help tag for

使用列表查詢名稱,然後針對個別語法、參數及預期輸出範例請求個別說明。

用法

使用 JSON 變數渲染模板:

knap render template.md --data article.json -o note.md

直接提供模板與資料:

knap render -t '# {{ title | trim }}' --data-json '{"title":"Hello"}'

覆蓋變數或透過管道傳遞 JSON 資料:

knap render template.md --data article.json --set 'title=Custom title'
cat article.json | knap render template.md --data -

資料必須是 JSON 物件;其屬性會成為模板變數。--set 會以字串覆蓋文字層級的鍵。巢狀物件、陣列、數字與布林值請使用 JSON。

選擇一個模板來源(檔案、-t 或 stdin)與一個資料來源(--data 或 --data-json)。只有一個輸入可以讀取 stdin。若沒有模板檔案或 -t,Knap 會從 stdin 讀取模板。

輸出預設為 stdout。-o 會在渲染成功後建立父目錄並覆寫目標檔案。錯誤時退出碼為 1;診斷訊息輸出至 stderr。警告可能在輸出成功時伴隨出現。

模板

使用 {{ variable }} 代表值,| 代表篩選器,{% ... %} 代表邏輯。例如,將以下內容儲存為 template.md:

---
{{ title | yaml_property:"title" }}
{{ tags | yaml_property:"tags" }}
---
# {{ title | trim }}
{% if author %}
By {{ author }}
{% endif %}

{{ content }}

使用 yaml_property 來處理完整的 frontmatter 屬性,確保值被正確引號與縮排。CLI 包含標準篩選器,但不提供 Web Clipper 瀏覽器變數、選擇器、提示詞或依賴 DOM 的 HTML 篩選器。請透過 JSON 提供變數。

在渲染前檢查模板:

knap validate template.md

驗證會檢查語法、篩選器名稱及靜態篩選器引數,不需要資料或檔案輸出。它不會檢查變數是否存在、執行時期值或動態引數;請使用真實資料進行渲染以檢查執行時期行為。診斷訊息會輸出至 stderr,並包含相關的說明指令。

Defuddle 管線

將網頁提取為包含 Markdown 內容的 JSON,再渲染成筆記:

defuddle parse https://example.com/article --md --json \
  | knap render template.md --data - -o note.md

Defuddle 的 JSON 屬性(例如 title 與 content)會直接成為模板變數。

批次渲染

為 CSV 每一行、JSON 陣列中每個物件或資料夾中每個 JSON 檔案各建立一個檔案:

knap batch template.md --data articles.csv --output-dir notes \
  --filename '{{ title | safe_name }}.md'

使用 --data articles.json 處理陣列,或使用 --data ./articles 處理資料夾中的 JSON 物件。CSV 標題會成為變數名稱,值保持為字串。管線資料預設為 JSON;對於管線 CSV 請加上 --format csv。

使用 --dry-run 來驗證並列出輸出路徑,但不實際寫入檔案。現有檔案需要 --overwrite,包括在試執行期間。批次中重複的輸出名稱即使使用 --overwrite 也會視為錯誤。

檔名模板必須產出單一檔案名稱及其副檔名,不可包含目錄。資料衍生的名稱請使用 safe_name。若未使用 --filename,Knap 會保留來源 JSON 的基礎名稱,或將 CSV 行與陣列項目標記為 1.md、2.md 等。

Individual skills in this repo

This repo contains 5 individual skills — each has its own dedicated page.

kepano/defuddle

Extract clean markdown content from web pages using Defuddle CLI, removing clutter and navigation to save tokens. Use instead of WebFetch when the user provides a URL to read or analyze, for online documentation, articles, blog posts, or any standard web page. Do NOT use for URLs ending in .md — those are already markdown, use WebFetch directly.

kepano/json-canvas

Create and edit JSON Canvas files (.canvas) with nodes, edges, groups, and connections. Use when working with .canvas files, creating visual canvases, mind maps, flowcharts, or when the user mentions Canvas files in Obsidian.

kepano/obsidian-bases

Create and edit Obsidian Bases (.base files) with views, filters, formulas, and summaries. Use when working with .base files, creating database-like views of notes, or when the user mentions Bases, table views, card views, filters, or formulas in Obsidian.

kepano/obsidian-cli

Interact with Obsidian vaults using the Obsidian CLI to read, create, search, and manage notes, tasks, properties, and more. Also supports plugin and theme development with commands to reload plugins, run JavaScript, capture errors, take screenshots, and inspect the DOM. Use when the user asks to interact with their Obsidian vault, manage notes, search vault content, perform vault operations from the command line, or develop and debug Obsidian plugins and themes.

kepano/obsidian-markdown

Create and edit Obsidian Flavored Markdown with wikilinks, embeds, callouts, properties, and other Obsidian-specific syntax. Use when working with .md files in Obsidian, or when the user mentions wikilinks, callouts, frontmatter, tags, embeds, or Obsidian notes.

相關技能