Skip to main content

MkDocs plugin and build pipeline for Markdown text projects with EPUB generation

Project description

text-forge

MkDocs plugin and build pipeline for text-based websites with EPUB generation, live editor, and GitHub integration.

PyPI Python License

Installation

As Python Package

pip install sg-text-forge

As GitHub Action

# .github/workflows/publish.yml
- uses: shared-goals/text-forge@main
  with:
    mkdocs_config: mkdocs.yml
    docs_dir: text/ru
    site_dir: public/ru

Quick Start

1. Configure MkDocs Plugin

Add to your mkdocs.yml:

plugins:
  - text-forge:
      editor_enabled: true          # Enable live editor (default: true)
      nobr_emoticons_enabled: true  # Wrap emoticons in no-break spans (default: true)
      downloads_enabled: false      # Show EPUB download button (default: false)
      ai_readable_enabled: false    # Show "Open in Perplexity" button (default: false)
      epub_title: "My Book"         # EPUB metadata (optional)
      epub_author: "Author Name"
      # ... other epub_* options

2. Build EPUB

text-forge epub --config=mkdocs.yml --build-dir=build

3. Build Complete Site

text-forge build --config=mkdocs.yml --build-dir=build

Features

๐Ÿ“ Live Editor Widget

  • Browser-based markdown editor with real-time preview
  • Pyodide + PyMdown Extensions for client-side rendering
  • Dual save modes:
    • mkdocs serve: Auto-saves to local filesystem
    • Production: Commits to GitHub via Personal Access Token
  • Split-pane interface with synchronized scrolling
  • Responsive design (mobile: editor only, desktop: split view)
  • i18n support (Russian translations included)

๐Ÿ”— GitHub Integration

  • GitHub API commits via Personal Access Token
  • Auto-triggers CI/CD workflows on commit
  • Path-safe writes with security validation
  • Local fallback when GitHub token unavailable

๐Ÿค– AI Agent Integration

  • "Open in Perplexity" button for AI-powered content analysis
  • Combined markdown export (text_combined.md) with all chapters
  • Normalized anchors and links for easy navigation
  • AI-readable format for semantic search and Q&A
  • Privacy-first: Disabled by default, opt-in via ai_readable_enabled

๐Ÿ“š EPUB Generation

  • Chapter combining from mkdocs.yml navigation structure
  • PyMdown โ†’ Pandoc syntax normalization via Lua filter
  • Metadata processing with git version/date extraction
  • Custom CSS styling for professional EPUB output
  • Asset bundling (images, resources)
  • Pandoc-based for wide e-reader compatibility

๐Ÿš€ GitHub Actions

  • Composite action (action.yml) for one-step publishing
  • Builds site + EPUB in single workflow
  • GitHub Pages deployment ready
  • Example: whattodo publish workflow

๐ŸŽจ Material Theme Integration

  • Auto-configures Material theme overrides
  • Custom partials: editor, downloads, header
  • Custom assets: editor.js, editor.css, translations.json
  • EPUB download button in header (when enabled)
  • Custom blocks: situation, music, chapter-dates, ...

CLI Commands

text-forge epub

Build EPUB from MkDocs project.

text-forge epub [OPTIONS]

Options:
  --config PATH      Path to mkdocs.yml (default: mkdocs.yml)
  --build-dir PATH   Build output directory (default: build)

text-forge build

Build complete site (EPUB + MkDocs site).

text-forge build [OPTIONS]

Options:
  --config PATH              Path to mkdocs.yml (default: mkdocs.yml)
  --build-dir PATH           Build directory (default: build)
  --site-dir PATH            MkDocs output (default: from mkdocs.yml)
  --strict/--no-strict       Fail on warnings (default: true)
  --copy-artifacts/--no-copy-artifacts
                             Copy EPUB to site root (default: true)
  --create-404-redirect/--no-create-404-redirect
                             Create 404.html for /ru/* redirects (default: true)

Plugin Configuration

MkDocs Plugin Options

plugins:
  - text-forge:
      # Editor
      editor_enabled: true                    # Show editor widget
      nobr_emoticons_enabled: true            # Wrap emoticons in md-nobr
      
      # Downloads
      downloads_enabled: false                # Show EPUB download button
      ai_readable_enabled: false              # Show "Open in Perplexity" button
      
      # EPUB Metadata (overrides site_name, site_author, etc.)
      epub_title: ""                          # Book title
      epub_subtitle: ""                       # Book subtitle
      epub_author: ""                         # Author name
      epub_identifier: ""                     # ISBN or URL
      epub_publisher: ""                      # Publisher name
      epub_rights: ""                         # Copyright notice
      
      # UI Labels
      source_file_published_title: "Published"  # Source link label
      
      # Theme
      auto_configure_theme: true              # Auto-set theme overrides

Development

Setup

git clone https://github.com/shared-goals/text-forge.git
cd text-forge
make install  # uv sync

Commands

make format      # Format code with ruff
make lint        # Run linters
make test        # Run tests with pytest
make check-i18n  # Validate translation keys
make release     # Interactive release (bump version, tag, push)

Project Structure

text-forge/
โ”œโ”€โ”€ text_forge/          # Python package
โ”‚   โ”œโ”€โ”€ plugin.py        # MkDocs plugin
โ”‚   โ”œโ”€โ”€ build.py         # Build pipeline
โ”‚   โ””โ”€โ”€ cli.py           # CLI commands
โ”œโ”€โ”€ scripts/             # Build scripts
โ”‚   โ”œโ”€โ”€ mkdocs-combine.py      # Chapter combiner
โ”‚   โ”œโ”€โ”€ pymdown-pandoc.lua     # Pandoc Lua filter
โ”‚   โ””โ”€โ”€ process-epub-meta.py   # Metadata processor
โ”œโ”€โ”€ mkdocs/
โ”‚   โ”œโ”€โ”€ overrides/       # Material theme overrides
โ”‚   โ”‚   โ”œโ”€โ”€ partials/    # HTML templates
โ”‚   โ”‚   โ””โ”€โ”€ assets/      # JS, CSS, translations
โ”‚   โ””โ”€โ”€ hooks/           # MkDocs hooks
โ”œโ”€โ”€ epub/                # EPUB templates
โ”‚   โ”œโ”€โ”€ book_meta.yml    # Metadata template
โ”‚   โ””โ”€โ”€ epub.css         # EPUB styles
โ”œโ”€โ”€ tests/               # Pytest tests

Example Projects

  • whattodo - Full example site with Russian content
  • Live demo - Published whattodo site

Requirements

  • Python โ‰ฅ 3.11
  • Pandoc (for EPUB generation)
  • MkDocs Material theme
  • Git (for version/date metadata)

License

MIT License - see LICENSE

Contributing

Contributions welcome! Please open issues or pull requests at github.com/shared-goals/text-forge.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sg_text_forge-0.1.12.tar.gz (92.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sg_text_forge-0.1.12-py3-none-any.whl (58.9 kB view details)

Uploaded Python 3

File details

Details for the file sg_text_forge-0.1.12.tar.gz.

File metadata

  • Download URL: sg_text_forge-0.1.12.tar.gz
  • Upload date:
  • Size: 92.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sg_text_forge-0.1.12.tar.gz
Algorithm Hash digest
SHA256 c2565af30268545f2ed977251a69e30568c5c99bea8c28fd55dbc9134bf9a503
MD5 ca5dd53d786ddab0b6f9d983c23adff5
BLAKE2b-256 36f2c8c70ca2e3f5ae39563b7a91d19bee88c48ce0f2193361f8d1f2f326ba1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for sg_text_forge-0.1.12.tar.gz:

Publisher: publish-pypi.yml on shared-goals/text-forge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sg_text_forge-0.1.12-py3-none-any.whl.

File metadata

  • Download URL: sg_text_forge-0.1.12-py3-none-any.whl
  • Upload date:
  • Size: 58.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sg_text_forge-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 4ead35ff9a917a9c3d975c5cb8b8458d28048b3c3a9ed44e6176ce00bb9612cf
MD5 1c3b193d345a000d6f42b7291d65cdb6
BLAKE2b-256 e54d501881ba473aa08846ca1d6ef59984166af729131e3e999307e17bcb3275

See more details on using hashes here.

Provenance

The following attestation bundles were made for sg_text_forge-0.1.12-py3-none-any.whl:

Publisher: publish-pypi.yml on shared-goals/text-forge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page