Convert content files to a styled PDF e-book: $ARGUMENTS
$ARGUMENTS should specify: the source file or directory path, and optionally: title, subtitle, author, output path, or style overrides. If no arguments, ask the user.
Before Starting
- Identify the source: single file or directory of files
- If a directory, determine file order (numeric prefixes, alphabetical, or custom)
- Read source files to understand content structure (headings, tables, lists, images)
- Check for any existing cover or metadata files
Process
- Gather content — Read all source files in order. For directories, sort by filename (numeric prefixes respected).
- Generate the conversion script — Write a Python script to
/tmp/pdf_ebook_convert.py that:
- Reads and concatenates all markdown/text/HTML files
- Converts markdown to HTML via the
markdown Python library (with tables, toc, fenced_code, meta extensions)
- Wraps in a full HTML document with embedded CSS
- Generates PDF via WeasyPrint
- Run the script — Execute with
python3 /tmp/pdf_ebook_convert.py
- Report — Show the output path and page count
Styling Defaults
The default e-book style uses:
- Page size: US Letter with 1in margins
- Body font: Georgia, serif at 11pt / 1.6 line-height
- Heading font: system sans-serif stack
- Colors: Dark charcoal text (#1a1a1a), accent for headings (#2c3e50)
- Tables: Clean bordered style with subtle header background
- Page breaks: Before each H1; avoid breaks inside tables, figures, blockquotes
- Header/footer: Running title in header, page numbers in footer
- Cover page: First page with title, subtitle, author centered
The user may override any of these via $ARGUMENTS (e.g., "dark theme", "A4 size", "sans-serif body").
Dependencies
Requires Python packages: weasyprint, markdown. Both should be installed. If missing, install with pip3 install weasyprint markdown.
Output
Default output path: same directory as source, named {title-slug}.pdf. User may specify a custom output path.
1---2name: pdf-ebook3description: Converts markdown, text, or HTML files into a styled PDF e-book using WeasyPrint, with support for directories, custom styling, and metadata.4---56Convert content files to a styled PDF e-book: $ARGUMENTS78$ARGUMENTS should specify: the source file or directory path, and optionally: title, subtitle, author, output path, or style overrides. If no arguments, ask the user.910## Before Starting11121. Identify the source: single file or directory of files132. If a directory, determine file order (numeric prefixes, alphabetical, or custom)143. Read source files to understand content structure (headings, tables, lists, images)154. Check for any existing cover or metadata files1617## Process18191. **Gather content** — Read all source files in order. For directories, sort by filename (numeric prefixes respected).202. **Generate the conversion script** — Write a Python script to `/tmp/pdf_ebook_convert.py` that:21 - Reads and concatenates all markdown/text/HTML files22 - Converts markdown to HTML via the `markdown` Python library (with `tables`, `toc`, `fenced_code`, `meta` extensions)23 - Wraps in a full HTML document with embedded CSS24 - Generates PDF via WeasyPrint253. **Run the script** — Execute with `python3 /tmp/pdf_ebook_convert.py`264. **Report** — Show the output path and page count2728## Styling Defaults2930The default e-book style uses:31- **Page size:** US Letter with 1in margins32- **Body font:** Georgia, serif at 11pt / 1.6 line-height33- **Heading font:** system sans-serif stack34- **Colors:** Dark charcoal text (#1a1a1a), accent for headings (#2c3e50)35- **Tables:** Clean bordered style with subtle header background36- **Page breaks:** Before each H1; avoid breaks inside tables, figures, blockquotes37- **Header/footer:** Running title in header, page numbers in footer38- **Cover page:** First page with title, subtitle, author centered3940The user may override any of these via $ARGUMENTS (e.g., "dark theme", "A4 size", "sans-serif body").4142## Dependencies4344Requires Python packages: `weasyprint`, `markdown`. Both should be installed. If missing, install with `pip3 install weasyprint markdown`.4546## Output4748Default output path: same directory as source, named `{title-slug}.pdf`. User may specify a custom output path.