← 返回 Skills 市场
waldekmastykarz

mdstr

作者 Waldek Mastykarz · GitHub ↗ · v0.2.0 · MIT-0
cross-platform ✓ 安全检测通过
106
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install 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...
使用说明 (SKILL.md)

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 \x3Cfile>

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

Flag Description
--preserve-newline Keep trailing newline in output (stripped by default)
--version Show version number
--help Show help with examples

Exit Codes

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

Common Workflows

Convert a markdown file to a JSON-safe string

mdstr instructions.md
# → "# Instructions\
\
Do this and that.\
\
Said \"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\
- 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.

安全使用建议
This skill appears benign for converting markdown into a JSON-safe string. Before using it, confirm that the npm package named mdstr is the one you intend to run, and only use the OpenAI/curl examples with files and API keys you are comfortable sending to that provider.
功能分析
Type: OpenClaw Skill Name: mdstr Version: 0.2.0 The skill bundle is a documentation-only package providing instructions for an AI agent to use the 'mdstr' CLI utility to convert markdown into JSON-safe strings. It contains no executable code, and the instructions in SKILL.md are consistent with the stated purpose, featuring standard usage examples and common integration patterns (e.g., using jq or curl) without any signs of malicious intent or prompt injection.
能力标签
requires-sensitive-credentials
能力评估
Purpose & Capability
The stated purpose is to convert user-supplied markdown files or stdin into a JSON-safe string, and the documented commands fit that purpose.
Instruction Scope
The instructions are mostly scoped to explicit file/stdin conversion, but they also show automated pipeline and OpenAI API examples that users should run only intentionally.
Install Mechanism
There is no install spec or reviewed code in the artifact set; the user is told to install or run an external npm package with npm/npx.
Credentials
The core converter needs no credentials, but one optional example uses an OpenAI API key and sends converted prompt content to OpenAI.
Persistence & Privilege
A global npm install would persist a binary in the user environment, but this is user-directed and no background process, privileged path, or ongoing persistence is described.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install mdstr
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /mdstr 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v0.2.0
Version 0.2.0 of mdstr introduces a comprehensive CLI tool for converting markdown to JSON-safe strings. - Adds zero-config CLI: convert markdown files or stdin to a single correctly escaped JSON string - Output is always JSON-quoted, with all special characters escaped (quotes, newlines, tabs, etc.) - Trailing newline stripped by default; `--preserve-newline` flag added - Deterministic exit codes for error handling (success, read/conversion error, invalid usage) - No interactive prompts, colors, or spinners—designed for automation - Extensive usage examples, API integrations, and error troubleshooting documented
元数据
Slug mdstr
版本 0.2.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

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... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 106 次。

如何安装 mdstr?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install mdstr」即可一键安装,无需额外配置。

mdstr 是免费的吗?

是的,mdstr 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

mdstr 支持哪些平台?

mdstr 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 mdstr?

由 Waldek Mastykarz(@waldekmastykarz)开发并维护,当前版本 v0.2.0。

💬 留言讨论