brewdoc:md-to-pdf
Use Cautionnpx machina-cli add skill kochetkov-ma/claude-brewcode/md-to-pdf --openclawMD to PDF
Converts Markdown files to professional PDF using one of two rendering engines.
Step 0: Parse Arguments
Parse $ARGUMENTS to determine mode and components.
| Component | Required | Description |
|---|---|---|
md_file | per mode | Path to .md file |
--engine | No | reportlab or weasyprint (overrides saved config) |
custom_prompt | No | Last argument in double quotes = LLM preprocessing instructions |
Mode detection rules:
| Condition | Mode |
|---|---|
Empty or help | HELP |
styles or config | STYLES |
test | TEST |
Path to .md file + quoted string at end | CONVERT+PROMPT |
Path to .md file (no quoted string) | CONVERT |
Extract --engine <name> from anywhere in arguments if present. Remove it before further parsing.
Step 1: Dependency Check
Resolve script paths using $BD_PLUGIN_ROOT:
$BD_PLUGIN_ROOT/skills/md-to-pdf/scripts/check_deps.sh$BD_PLUGIN_ROOT/skills/md-to-pdf/scripts/md_to_pdf.py
Determine the target engine (from --engine flag, saved config, or default reportlab).
EXECUTE using Bash tool:
bash "$BD_PLUGIN_ROOT/skills/md-to-pdf/scripts/check_deps.sh" check ENGINE_NAME 2>&1; echo "EXIT_CODE=$?"
Replace ENGINE_NAME with the target engine.
If output contains MISSING_PIP or MISSING_SYSTEM:
Use AskUserQuestion presenting the engine comparison table:
| Feature | reportlab | weasyprint |
|---|---|---|
| Install | pip only | pip + brew |
| Quality | Good | Excellent |
| Speed | Fast | Moderate |
| Images | Basic | Full |
| CSS Styling | No | Yes |
| Code highlight | No | Yes (Pygments) |
Options:
- "Install ENGINE_NAME dependencies"
- "Switch to OTHER_ENGINE" (if the other engine is available)
- "Cancel"
If user chooses install, EXECUTE using Bash tool:
bash "$BD_PLUGIN_ROOT/skills/md-to-pdf/scripts/check_deps.sh" install ENGINE_NAME 2>&1 && echo "---INSTALL_OK---" || echo "---INSTALL_FAILED---"
STOP if INSTALL_FAILED -- report error and exit.
If user cancels -- STOP.
Step 2: Engine Selection (first run only)
Check for saved config in order:
- Project:
.claude/md-to-pdf.config.json - Global:
~/.claude/md-to-pdf.config.json
If --engine flag was provided -- use it (skip config lookup).
If no saved preference and no --engine flag -- use AskUserQuestion with the engine comparison table from Step 1. Save the choice:
{
"engine": "reportlab",
"pygments_theme": "github"
}
Write to project config .claude/md-to-pdf.config.json (create .claude/ dir if needed).
Step 3: Mode Execution
HELP Mode
Print formatted usage:
MD to PDF Converter
Usage:
/brewdoc:md-to-pdf <file.md> Convert with saved engine/style
/brewdoc:md-to-pdf <file.md> --engine weasyprint Convert with specific engine
/brewdoc:md-to-pdf <file.md> "remove section X" Preprocess MD then convert
/brewdoc:md-to-pdf styles Configure page/color/font
/brewdoc:md-to-pdf test Convert bundled test file
/brewdoc:md-to-pdf help Show this help
Engines:
reportlab -- Pure Python, fast, no system deps (pip install reportlab)
weasyprint -- HTML/CSS pipeline, best quality (pip + brew deps)
EXIT after printing.
CONVERT Mode
- Read the input MD file with Read tool. If not found -- STOP with error.
- Determine output path: same directory, same name,
.pdfextension. - Build the config path argument (if project or global config exists, add
--config CONFIG_PATH).
EXECUTE using Bash tool:
python3 "$BD_PLUGIN_ROOT/skills/md-to-pdf/scripts/md_to_pdf.py" "INPUT_PATH" "OUTPUT_PATH" --engine ENGINE --quiet 2>&1 && echo "---CONVERT_OK---" || echo "---CONVERT_FAILED---"
Replace INPUT_PATH, OUTPUT_PATH, ENGINE with actual values. Add --config CONFIG_PATH if a style config JSON exists. Add --pygments-theme THEME for weasyprint if configured.
STOP if CONVERT_FAILED -- read error output, attempt fix, retry once. If still failing -- report error.
- Parse structured output lines:
STATUS,OUTPUT,PAGES,SIZE,ENGINE.
CONVERT+PROMPT Mode
- Read the input MD file with Read tool.
- Apply LLM transformations per the
custom_promptinstructions (delete sections, rewrite headings, restructure, etc.). - Write modified content to temp file:
{original_dir}/.tmp_{original_name}.md - Run the converter on the temp file (same command as CONVERT mode, using temp file as input, original name for output).
- Delete the temp file.
EXECUTE using Bash tool:
rm -f "TEMP_FILE_PATH"
- Proceed to Step 4 with
preprocessing: true.
STYLES Mode
Run interactive configuration via AskUserQuestion dialogs:
Question 1 -- Page size:
Options: A4 (default), Letter, Legal
Question 2 -- Color scheme:
Options: Default blue (primary #1a3a5c), Dark (primary #2d3748), Custom (ask for hex values)
Question 3 -- Code theme (weasyprint only):
Options: github (default), monokai, friendly, solarized-dark, solarized-light
Question 4 -- Footer format:
Options: Page {page} of {total} (default), {page}/{total}, Disabled
Build JSON config matching styles/default.json structure, overriding changed values. Write to .claude/md-to-pdf.config.json.
Report saved settings table and EXIT.
TEST Mode
- Use bundled test file:
$BD_PLUGIN_ROOT/skills/md-to-pdf/test/test-all-elements.md - Determine output path:
/tmp/md-to-pdf-test-ENGINE.pdf - Run converter (same command as CONVERT mode, using test file as input,
/tmp/output). - Proceed to Step 4.
Step 4: Report Results
| Parameter | Value |
|---|---|
| Source | absolute path to input MD |
| Output | absolute path to output PDF |
| Pages | from PAGES= in script output |
| Size | from SIZE= in script output |
| Engine | reportlab or weasyprint |
| Preprocessing | custom_prompt summary (if used) or none |
Source
git clone https://github.com/kochetkov-ma/claude-brewcode/blob/main/brewdoc/skills/md-to-pdf/SKILL.mdView on GitHub Overview
Converts Markdown files into professional PDFs using either a lightweight rendering engine (reportlab) or a full HTML/CSS pipeline (weasyprint). It supports style customization, dependency management, and a test mode to ensure quality before production. Triggers include pdf, md to pdf, markdown to pdf, convert pdf, and generate pdf to streamline workflows.
How This Skill Works
The skill parses arguments to determine the operation mode and target MD file, then checks and installs dependencies as needed. It chooses the rendering engine from --engine, saved config, or the default (reportlab), and renders the Markdown to PDF, applying CSS styles if using weasyprint. The resulting PDF is written alongside the source MD file (or per configured output).
When to Use It
- You need a fast, lightweight PDF from MD for internal docs (use reportlab).
- You require polished PDFs with CSS-driven layouts and images (use weasyprint).
- You want to lock in engine and style preferences for a team workflow (save config).
- You need to validate dependencies or test in TEST mode before rendering (TEST).
- You want to preprocess the MD with an LLM prompt before converting (CONVERT+PROMPT).
Quick Start
- Step 1: Read the input Markdown file with the Read tool.
- Step 2: Run the converter, selecting an engine or using saved config.
- Step 3: Retrieve the PDF in the same directory as the MD file (or the configured output path).
Best Practices
- Pin engine choice to avoid drift by using --engine or a saved config.
- Use the STYLES mode to iterate typography, page size, and color before rendering.
- Run in TEST mode to verify dependencies and environment first.
- Organize outputs in a dedicated docs/builds folder to keep repos clean.
- For weasyprint, ensure system dependencies (like Brew) are installed for full CSS support.
Example Use Cases
- /brewdoc:md-to-pdf docs/intro.md
- /brewdoc:md-to-pdf docs/whitepaper.md --engine weasyprint
- /brewdoc:md-to-pdf docs/company-brand.md styles
- /brewdoc:md-to-pdf test
- /brewdoc:md-to-pdf docs/guide.md "Remove sections X before render"