top

License: MIT

mdctl

A command-line tool for processing Markdown files. Currently, it supports automatically downloading remote images to local storage and updating the image references in Markdown files, as well as translating markdown files using AI models.

Key Features

Installation

Use Homebrew to install mdctl. Follow the Homebrew Installation Guide to install Homebrew.

brew tap samzong/tap
brew install samzong/tap/mdctl

Or use go to install mdctl.

go install github.com/samzong/mdctl@latest

Usage

Quick examples for common tasks:

Downloading Images

# Process a single file
mdctl download -f path/to/your/file.md

# Process a directory
mdctl download -d path/to/your/directory

Translating I18n

# Translate to Chinese
mdctl translate -f README.md -l zh

# Translate a directory to Japanese
mdctl translate -d docs/ -l ja

Uploading Images to Cloud Storage

# Upload images from a file
mdctl upload -f post.md

# Upload images from a directory
mdctl upload -d docs/

Exporting Documents to .docx

# Export to DOCX
mdctl export -f README.md -o output.docx

# Export to PDF with table of contents
mdctl export -d docs/ -o documentation.pdf -F pdf --toc

Generating llms.txt from sitemap.xml

# Standard mode (titles and descriptions)
mdctl llmstxt https://example.com/sitemap.xml > llms.txt

# Full-content mode
mdctl llmstxt -f https://example.com/sitemap.xml > llms-full.txt

Command Reference

download

Downloads and localizes remote images in Markdown files.

Parameters:

translate

The translate command allows you to translate markdown files or directories to a specified language using AI models.

Supported AI Models

Supported Languages

Configuration

Create a configuration file at ~/.config/mdctl/config.json with the following content:

{
  "translate_prompt": "Please translate the following markdown content to {TARGET_LANG}, keep the markdown format and front matter unchanged:",
  "endpoint": "your-api-endpoint",
  "api_key": "your-api-key",
  "model": "gpt-3.5-turbo",
  "temperature": 0.0,
  "top_p": 1.0
}

Or use the config command to set up:

# Set API endpoint
mdctl config set -k endpoint -v "your-api-endpoint"

# Set API key
mdctl config set -k api_key -v "your-api-key"

# Set model
mdctl config set -k model -v "gpt-3.5-turbo"

Features:

upload

The upload command uploads local images in markdown files to cloud storage and rewrites URLs to reference the uploaded versions.

Features:

Parameters:

export

The export command converts markdown files to various document formats like DOCX, PDF, and EPUB using Pandoc as the underlying conversion tool.

Features:

Parameters:

llmstxt

The llmstxt command generates a markdown-formatted text file from a website's sitemap.xml, which is ideal for training or fine-tuning language models.

Features:

Parameters:

Notes

  1. -f and -d parameters cannot be used together
  2. If no output directory is specified, the tool will automatically create a default images directory
  3. Only remote images (http/https) will be processed, local image references will not be modified
  4. Image filenames will retain their original names, if duplicates occur, a hash of the URL will be added as a suffix