docster/CLAUDE.md
Your Name dda2fc15b2 Update docs and install script for Stack/GHC 9.10.3
Switch README and CLAUDE.md from cabal to stack commands, update GHC
version references, add pkg-config to install-deps.sh, and add Stack
as the recommended build method.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 21:27:36 +00:00

2.2 KiB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

Docster is a Haskell CLI tool that converts Markdown files with embedded Mermaid diagrams into PDF or HTML. It processes Mermaid code blocks by rendering them to SVG images and embedding them in the output.

Development Commands

Build

stack build

Run

# Convert to PDF
stack exec docster -- -pdf path/to/file.md

# Convert to HTML
stack exec docster -- -html path/to/file.md

Test

stack test

Test a single file

stack exec docster -- -pdf mermaid-to-svg/sample.md

Clean build artifacts

stack clean

Interactive development

stack repl

Architecture

The application consists of:

  1. Main.hs (app/Main.hs:1-69) - Entry point and core logic
    • processMermaidBlock (app/Main.hs:54-79) - Transforms Mermaid code blocks into images (SVG for HTML, high-res PNG for PDF)
    • transformDoc (app/Main.hs:36-37) - Walks the Pandoc AST to process all blocks
    • compileToPDF (app/Main.hs:47-58) - Converts Markdown to PDF using LaTeX
    • compileToHTML (app/Main.hs:60-68) - Converts Markdown to HTML

The tool uses Pandoc's AST transformation capabilities to:

  1. Parse Markdown input
  2. Find Mermaid code blocks
  3. Generate image files using mermaid-cli (mmdc) - SVG for HTML, high-resolution PNG for PDF
  4. Replace code blocks with image references
  5. Output final PDF/HTML

Dependencies

External requirements:

  • Stack (install via ghcup) — manages GHC 9.10.3 automatically via lts-24.34
  • Pandoc library (Haskell dependency, pulled by Stack)
  • TeX Live (for PDF generation via XeLaTeX)
  • Mermaid CLI (npm install -g @mermaid-js/mermaid-cli)
  • pkg-config, libgmp-dev, libffi-dev, zlib1g-dev (see install-deps.sh)

Common Issues

  1. Missing LaTeX packages: PDF generation requires a LaTeX distribution. Install BasicTeX or TinyTeX and use tlmgr to add packages as needed.

  2. Mermaid CLI not found: Ensure mmdc is in PATH after installing @mermaid-js/mermaid-cli globally.

  3. Type errors with Text vs String: The codebase mixes Data.Text and String. Use T.pack/T.unpack for conversions.