← 返回
未分类

mdstr

This skill should be used when the user asks to "convert markdown to JSON string", "escape markdown for JSON", "make markdown JSON-safe", "embed markdown in...
用于在用户请求将 Markdown 转换为 JSON 字符串、转义 Markdown 为 JSON、让 Markdown 符合 JSON 安全或将其嵌入…时使用。
waldekmastykarz
未分类 clawhub v0.2.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 262
下载
💾 0
安装
1
版本
#latest

概述

mdstr - Markdown to JSON-safe String

Zero-config CLI for converting markdown to a JSON-safe string. Pass a file or pipe stdin, get a properly escaped JSON string on stdout. No flags required.

Prerequisites

Ensure mdstr is available:

# Check if installed
which mdstr

# Install globally if needed
npm install -g mdstr

# Or use npx for one-off conversions
npx mdstr <file>

Requires Node.js 20 or later.

Basic Usage

From a file

mdstr README.md
mdstr ./docs/guide.md

From stdin

cat notes.md | mdstr
echo '# "Hello" World' | mdstr
# → "# \"Hello\" World"

The output is always a single JSON string on stdout, surrounded by quotes, with all special characters properly escaped. Ready to embed directly into JSON structures.

Options

FlagDescription
------
--preserve-newlineKeep trailing newline in output (stripped by default)
--versionShow version number
--helpShow help with examples

Exit Codes

CodeMeaning
------
0Success
1Read/conversion error
2Invalid usage (file not found, no input)

Common Workflows

Convert a markdown file to a JSON-safe string

mdstr instructions.md
# → "# Instructions\n\nDo this and that.\n\nSaid \"hello\" and left."

Embed markdown in a JSON payload

Use jq to build JSON structures with markdown content:

jq -n --argjson content "$(mdstr instructions.md)" '{prompt: $content}' > payload.json

Inject markdown into LLM prompts

SYSTEM_PROMPT=$(mdstr system-prompt.md)
curl -s https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d "$(jq -n --argjson prompt "$SYSTEM_PROMPT" '{
    model: "gpt-4o",
    messages: [{role: "system", content: $prompt}]
  }')"

Build payloads from multiple markdown files

jq -n \
  --argjson system "$(mdstr system.md)" \
  --argjson user "$(mdstr user-prompt.md)" \
  '{messages: [{role: "system", content: $system}, {role: "user", content: $user}]}'

Pipe markdown into JSON

echo '- line 1
- line 2' | mdstr | jq '{content: .}'
# → {"content": "- line 1\n- line 2"}

Keep trailing newline

By default, mdstr strips the trailing newline. To preserve it:

mdstr README.md --preserve-newline

Output Characteristics

The output is always:

  • A single JSON string on stdout (with surrounding quotes)
  • All special characters escaped (", \, newlines, tabs, etc.)
  • Trailing newline stripped by default (use --preserve-newline to keep)
  • Errors on stderr
  • Deterministic exit codes

No confirmation prompts. No color codes. No spinners. Designed for automated pipelines and agent tool calls.

Error Handling

When conversion fails, check:

  1. File exists and is readable
  2. Input is provided (either a file argument or piped stdin)
  3. Node.js 20 or later is installed

Errors are printed to stderr with actionable context.

Use Cases

API payloads

Convert markdown documentation or prompts into JSON-safe strings for REST API calls:

mdstr prompt.md
# Use the output directly in curl or httpie commands

LLM prompt construction

Convert system prompts, user messages, or few-shot examples stored as markdown files into strings suitable for LLM API payloads.

Configuration files

Embed markdown content (descriptions, help text, documentation) into JSON config files.

CI/CD pipelines

Convert release notes or changelogs from markdown to JSON-safe strings for automated notifications or API integrations.

版本历史

共 1 个版本

  • v0.2.0 当前
    2026-05-21 14:25 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

developer-tools

gitload

waldekmastykarz
此技能应在用户请求“下载 GitHub 文件”“从仓库获取文件夹”“获取 GitHub 代码”或“下载 GitHub仓库”时使用。
★ 3 📥 3,477

atifact

waldekmastykarz
当用户请求“提取代理轨迹”、“将HAR转换为轨迹”、“从会话获取轨迹”或“解析代理会话”时使用此技能。
★ 0 📥 277

jyml

waldekmastykarz
当用户请求将YAML转换为JSON、将JSON转换为YAML、转换YAML文件、转换JSON文件或转换配置时使用此技能。
★ 0 📥 269