npm.io
0.2.0 • Published yesterday

@cmtx/template

Licence
Apache-2.0
Version
0.2.0
Deps
0
Size
48 kB
Vulns
0
Weekly
0
Stars
4

CMTX Logo - seal script character 文 (wén)

CMTX — Composable Markdown Toolkit

The logo features (wén) — from Chinese, meaning "text" or "writing", rendered in traditional seal script (篆书).

Composable Markdown document processing toolkit: asset pipelines, content transforms, metadata management, cross-platform adaptation.
Use as an npm library, CLI batch processor, VS Code extension, or connect to AI agents via MCP Server.


License

Package Version
@cmtx/core npm version
@cmtx/asset npm version
@cmtx/rule-engine npm version
@cmtx/ai npm version
@cmtx/autocorrect-wasm npm version
@cmtx/storage npm version
@cmtx/template npm version
@cmtx/fpe-wasm npm version
@cmtx/markdown-it-presigned-url npm version
@cmtx/markdown-it-presigned-url-adapter-nodejs npm version
@cmtx/cli npm version
@cmtx/mcp-server npm version
cmtx-vscode npm version

What is CMTX?

CMTX is a pnpm workspace monorepo providing out-of-the-box Markdown document processing capabilities.

Core capabilities:

Capability Description
Asset Pipeline Image extraction, upload, transfer, download, removal + smart deduplication + reference replacement
Metadata Management YAML frontmatter parse/update/delete, heading extraction, auto-generated ID/date/updated fields
Content Transforms Section numbering, heading promotion, text replacement, image format conversion (Markdown HTML)
Cross-Platform Adaptation Adapt Markdown to different platform formats via rule engine + presets
Rule Engine Programmable content transform pipeline with preset orchestration
Encrypted Asset IDs NIST SP 800-38G FF1 format-preserving encryption, optional Luhn check digit
Pre-signed URLs Auto-generated temporary access links for private bucket images in editors
AI Agent Integration MCP Server for Claude, Cursor, and other AI agents to manage Markdown assets

Delivery channels:

Channel Description
npm libraries @cmtx/core, @cmtx/asset, etc. — import in your code
CLI @cmtx/cli — batch processing from the command line
VS Code Extension cmtx-vscode — visual operations in the editor
MCP Server @cmtx/mcp-server — connect to AI agents

Quick Start

CLI
# Install globally
npm install -g @cmtx/cli

# Scan and analyze images in docs
cmtx analyze images ./docs

# Upload local images to cloud storage
cmtx image upload ./docs --provider aliyun-oss --region oss-cn-hangzhou --bucket my-bucket

# Publish with a preset
cmtx publish ./article.md --preset my-blog --to-dir ./output

# Format images in a document
cmtx format ./article.md --to html --width 800

# Manage section numbers
cmtx section-numbers add ./article.md
cmtx section-numbers remove ./article.md

# Pack / unpack document with assets
cmtx pack ./article.md
cmtx unpack ./archive.zip

See docs/i18n/zh-Hans/cli/USR-002-commands-reference.md for the full command reference.

VS Code Extension

Search for "CMTX" in the VS Code marketplace. Supports image upload/download, resize, format conversion, and platform adaptation via GUI. Keyboard shortcuts: Ctrl+Shift+H toggle format, Ctrl+Up/Ctrl+Down zoom.

AI Agent Integration (MCP)
{
    "mcpServers": {
        "cmtx": {
            "command": "npx",
            "args": ["-y", "@cmtx/mcp-server"]
        }
    }
}

Once configured, AI agents can scan Markdown files, upload images to cloud storage, update references, and clean up unused assets.

As an npm Library
import { filterImages, updateImageRefs } from "@cmtx/core";
import { createAdapter } from "@cmtx/storage";
import { ConfigBuilder } from "@cmtx/asset/upload";

Package Overview

Package Description
@cmtx/core Markdown text processing core: image parse/replace, frontmatter, section numbering
@cmtx/asset Asset pipeline: upload, transfer, download, remove, config loading, ID generation
@cmtx/rule-engine Rule engine, content transforms, metadata, cross-platform adaptation
@cmtx/ai AI capabilities: slug generation, agent orchestration
@cmtx/autocorrect-wasm Text autocorrection via WebAssembly
@cmtx/storage Cloud storage adapters (Aliyun OSS, Tencent COS)
@cmtx/template Template rendering engine
@cmtx/fpe-wasm NIST SP 800-38G FF1 format-preserving encryption (WASM)
@cmtx/markdown-it-presigned-url Markdown-it pre-signed URL plugin (async signing + cache callback)
@cmtx/markdown-it-presigned-url-adapter-nodejs Node.js signing adapter (OSS/S3 signer + LRU cache)
@cmtx/cli Command-line tool
@cmtx/mcp-server MCP server for AI agent integration
cmtx-vscode VS Code extension

Architecture

Layer 6: Application Layer (User-facing)
  @cmtx/cli  @cmtx/mcp-server  cmtx-vscode

Layer 5: Processing Layer
  @cmtx/rule-engine           — rule engine, content transforms, metadata

Layer 4: AI Capabilities
  @cmtx/ai                    — slug generation, agent orchestration

Layer 3: Business Orchestration
  @cmtx/asset                 — upload/transfer/download/remove pipeline, config management, ID generation

Layer 2: Tooling
  @cmtx/markdown-it-presigned-url*  — pre-signed URL plugin

Layer 1: Foundation
  @cmtx/core  @cmtx/template  @cmtx/storage  @cmtx/fpe-wasm  @cmtx/autocorrect-wasm

Dependencies are strictly unidirectional with no circular dependencies.


Feature Matrix

Domain Capability Package
Image Parsing Extract Markdown/HTML images, filter by source/domain/path @cmtx/core
Image Replacement Replace src/alt/title, supports Markdown and HTML syntax @cmtx/core
Section Numbering Add / remove heading level numbers (add also strips existing numbers) @cmtx/core
Frontmatter Parse, inject, delete YAML frontmatter fields @cmtx/core
Image Upload Upload to cloud storage, dedup, template naming @cmtx/asset
Image Transfer Copy/move remote images between storage services @cmtx/asset
Image Download Download remote images to local, domain filtering @cmtx/asset
Safe Deletion Reference-checked deletion (trash/move/hard-delete) @cmtx/asset
Config Management YAML config loading, env var substitution @cmtx/asset
ID Generation UUID / slug / counter / FF1 encrypted IDs @cmtx/asset
Cloud Storage Unified adapter (Aliyun OSS, Tencent COS) @cmtx/storage
Template Engine {variable} template rendering, Builder pattern @cmtx/template
Rule Engine Extensible preset content transform system @cmtx/rule-engine
Slug Generation AI-powered semantic slug generation @cmtx/ai
Text Correction CJK text autocorrection (WASM) @cmtx/autocorrect-wasm
Cross-Platform Adaptation Adapt Markdown to different formats via presets (WeChat preset implemented) @cmtx/rule-engine
Pre-signed URLs markdown-it async pre-signed URL generation @cmtx/markdown-it-presigned-url
MCP Server JSON-RPC 2.0 standard, direct AI agent invocation @cmtx/mcp-server
CLI Full command-line interface @cmtx/cli
VS Code Extension Integrated GUI, command palette, keyboard shortcuts cmtx-vscode

Project Structure

cmtx-project/
├── packages/
│   ├── core/              # Markdown text processing
│   ├── asset/             # Asset pipeline (upload/transfer/download/remove)
│   ├── rule-engine/       # Rule engine + cross-platform adaptation
│   ├── ai/                # AI capabilities: slug, orchestration
│   ├── storage/           # Cloud storage adapters
│   ├── template/          # Template rendering
│   ├── fpe-wasm/          # Format-preserving encryption (WASM)
│   ├── autocorrect-wasm/  # Text autocorrection (WASM)
│   ├── cli/               # Command-line tool
│   ├── mcp-server/        # MCP server
│   ├── vscode-extension/  # VS Code extension
│   ├── markdown-it-presigned-url/          # Pre-signed URL plugin
│   └── markdown-it-presigned-url-adapter-nodejs/  # Signing adapter
├── docs/                  # Documentation
└── scripts/               # Build and release scripts

Development

Prerequisites
  • Node.js >= 22
  • pnpm >= 10
Local Development
pnpm install
pnpm build
pnpm test
pnpm lint
pnpm typecheck
Module System

All packages are written in strict ESM. Build output includes both ESM (.mjs) and CJS (.cjs) formats.


Documentation

License

Apache 2.0

Keywords