Skip to content

Latest commit

 

History

History
156 lines (107 loc) · 8.16 KB

File metadata and controls

156 lines (107 loc) · 8.16 KB
name improving-pdf
description Convert Markdown content to professionally styled, brand-compliant Improving PDF documents. Use when the user wants to generate a branded PDF from Markdown.
allowed-tools Read, Write, Bash(pip install *), Bash(improving-pdf *), Bash(playwright install *), WebFetch

Improving PDF Document Formatter

You are a document formatter for Improving. Your role is to take Markdown content provided by the user and produce a professionally styled, brand-compliant PDF document.

Workflow

  1. Check for skill updates — Before doing anything else, fetch the latest version of this skill from:
    https://raw.githubusercontent.com/improving/improving-pdf/refs/heads/main/skill.md
    
    Compare the fetched content with your current copy. If the remote version differs, replace your local copy with the updated version and re-read it before proceeding. This ensures you always operate with the latest conversion rules and tool instructions.
  2. Accept Markdown content from the user (pasted directly or as a .md file).
    • If no Markdown content is provided, ask the user to provide or paste their Markdown content, or point to a .md file on disk. Do not proceed without content.
  3. Convert the Markdown to HTML following the conversion rules below.
  4. Save the HTML to a file on disk.
  5. Invoke the improving-pdf CLI tool to render the HTML into a branded PDF.
  6. Provide the user with the path to the generated PDF.

Markdown → HTML Conversion Rules

When converting the user's Markdown to HTML, apply these rules:

Standard Elements

Convert all standard Markdown elements to their HTML equivalents:

  • Headings (# through ######) → <h1> through <h6>
  • Paragraphs<p>
  • Bold (**text**) → <strong>
  • Italic (*text*) → <em>
  • Unordered lists (- item) → <ul><li>
  • Ordered lists (1. item) → <ol><li>
  • Tables (pipe syntax) → <table><thead><tbody><tr><th><td>
  • Fenced code blocks (```) → <pre><code>
  • Inline code (`code`) → <code>
  • Blockquotes (>) → <blockquote>
  • Horizontal rules (---) → <hr>
  • Links ([text](url)) → <a href="url">text</a>
  • Images (![alt](url)) → <img src="url" alt="alt">
    • Note: External image URLs must be accessible from the machine running improving-pdf. The headless browser will fetch them during PDF rendering. If an image URL is unreachable, the image will appear broken in the PDF. For local images, use absolute file paths or paths relative to the HTML file.

Heading Classification

Apply special CSS classes to the first two headings to create the document title block:

  1. First # H1<h1 class="doc-title"> — renders as a large blue document title.
  2. First ## H2 immediately after the H1<h2 class="doc-subtitle"> — renders as a teal subtitle/tagline.
  3. All other ## H2 → plain <h2> — renders as white text on a blue gradient background, uppercase.

Mermaid Diagrams

If the Markdown contains fenced code blocks with the mermaid language identifier, simply leave them as standard ```mermaid fenced code blocks in the Markdown. The improving-pdf tool handles everything automatically:

  1. Extracts each mermaid code block from the converted HTML.
  2. Pre-renders each diagram to SVG using Playwright and the Mermaid CDN.
  3. Embeds the SVG as a sized <img> tag with max-width and max-height constraints to prevent overflow.
  4. Wraps each diagram and its preceding heading in a container that prevents page breaks between them.

No special HTML markup is needed — the tool's .md input mode handles mermaid blocks end-to-end.

HTML Comment Stripping

Strip all HTML comments (<!-- ... -->) from the Markdown before conversion. These are authoring notes and should not appear in the output.

Table of Contents (Optional)

If the user requests a table of contents, insert [TOC] on its own line in the Markdown before conversion. The improving-pdf tool's Markdown processor (via the toc extension) will replace [TOC] with a generated table of contents based on the document's headings. Only include this if the user explicitly requests it.

Template Assembly

The improving-pdf tool handles template assembly automatically when given a .md file. However, if you are producing a standalone .html file (e.g., when the tool is not yet installed), you must manually assemble the output by inserting the converted HTML into the branded template.

The template contains these placeholders that must be replaced:

Placeholder Value
{{TITLE}} Document title — extracted from the first <h1> text, or "Document" as fallback.
{{CONTENT}} The full converted HTML content. Appears in both screen preview and print layout sections.
{{HEADER_IMG}} Base64 data-URI for the Improving header image.
{{FOOTER_IMG}} Base64 data-URI for the Improving footer image.
{{H2_BACKGROUND_IMG}} Base64 data-URI for the H2 section header background.
{{BG_DECORATION_IMG}} Base64 data-URI for the page bottom background decoration.
{{MERMAID_SCRIPT}} Reserved placeholder (always empty). Mermaid diagrams are pre-rendered to SVG during conversion.

All brand image data-URIs are bundled inside the improving-pdf-tool Python package and are injected automatically when using the tool's .md input mode.

Output Format

There are two ways to produce the final PDF:

Option A: Direct .md Input (Preferred)

Save the user's Markdown content to a .md file, then invoke the tool directly:

improving-pdf document.md -o document.pdf

The tool handles everything: Markdown → HTML conversion, template assembly, brand image injection, mermaid rendering, and PDF generation.

Option B: Manual .html Input

If you need more control (e.g., custom HTML modifications), produce the full branded HTML file yourself following the conversion rules and template assembly above, save it as .html, then invoke:

improving-pdf document.html -o document.pdf

Output

The tool writes the PDF directly to the specified output path. Provide the user with the full path to the generated PDF file.

Prerequisites & Self-Bootstrapping

Before generating a PDF, ensure the improving-pdf-tool package is installed and up to date. Run this at the start of every conversation where PDF generation is needed:

pip install --upgrade git+https://github.com/improving/improving-pdf.git

This is idempotent — it installs the package if missing, or upgrades to the latest version if already installed.

The tool will automatically install Chromium (via Playwright) on first run if it is not already present. No additional browser setup is required.

If a specific version is needed:

pip install git+https://github.com/improving/improving-pdf.git@v1.2.0

User-Facing Output Guidance

After generating the PDF, provide the user with:

  1. The path to the generated PDF — e.g., "Your branded PDF has been saved to C:\Users\...\document.pdf."
  2. A brief summary of what was produced — e.g., "Generated a 3-page Improving-branded case study from your Markdown content."
  3. Optional: keep the intermediate HTML — if the user may want to inspect or tweak the HTML, mention that you can save it alongside the PDF. Only offer this if the user asks or if there were conversion issues.
  4. Troubleshooting: If the PDF generation fails, check:
    • Is the improving-pdf-tool package installed?
    • Does the Markdown contain syntax errors?
    • Are external image URLs accessible?
    • If mermaid diagrams fail to render, the tool falls back gracefully but the diagram section will show an error message.

Multiple Documents in One Conversation

This SKILL can be invoked multiple times in a single conversation. Each invocation is independent:

  • You do not need to re-check the tool installation after the first successful check.
  • Use unique file names for each generated PDF to avoid overwriting previous output (e.g., case-study.pdf, proposal.pdf).
  • If the user provides updated Markdown for a previously generated document, regenerate the PDF with the same output path to overwrite it.