A library and CLI to convert Markdown to Epub
Project description
md2epub
md2epub is a helper library and CLI tool designed to convert Markdown text into professional, publish-ready EPUB files. It specifically targets formatting standards suitable for KDP (Kindle Direct Publishing), ensuring strict ordering of content (Cover, Title, Copyright, TOC, Dedication, Chapters).
Features
- Project Scaffolding: Quickly initialize a book directory with a standard structure using Cookiecutter templates.
- Markdown to EPUB: Converts Markdown content into XHTML with a generated navigation structure.
- KDP-Ready Styling: Includes a CSS template optimized for e-readers, handling fonts, margins, and scene breaks.
- Custom Formatting: specific support for novel formatting:
xxxon a single line creates a centered Scene Break.***on a single line creates a centered Asterisk Break.
Guide for Writers
1. Installation
Ensure you have Python 3.12 or higher installed.
pip install md2epub
2. Creating a New Book
To start a new project, use the init command. This creates a folder with all the necessary configuration files and templates.
md2epub init my_new_book
You will be prompted for basic details (Book Name, Author Name, Dedications, etc.) which are used to configure the project.
3. Writing Your Content
Navigate to your new book directory. You will see several markdown files (e.g., chapter_01.md, title.md). Write your book using standard Markdown.
Formatting Tips:
- Chapters: Start chapters with a header
# Chapter Title. - Scene Breaks: To insert a visible break in the text, place
xxxon its own line. - Asterisks: To insert a decorative break, place
***on its own line.
4. Configuration (metadata.yaml)
The metadata.yaml file controls the build process. You must list every file you want to include in the EPUB here.
title: "My Great Novel"
author: "Jane Doe"
language: en
cover_image: cover.png
front_matter:
- title.md
- copyright.md
- dedication.md
chapters:
- chapter_01.md
- chapter_02.md
5. Compiling the EPUB
When you are ready to generate your book:
md2epub compile my_new_book
This will generate an .epub file in the current directory.
Guide for Developers
Development Setup
- Clone the repository.
- Install the package in editable mode with development dependencies.
python -m pip install --upgrade pip
pip install -e .[dev]
Running Tests
The project uses pytest for testing. A custom script scripts/run_tests.py is provided to run tests and enforce coverage thresholds.
python scripts/run_tests.py
- Failure Threshold: The build fails if more than 20% of tests fail.
- Coverage Threshold:
- Codebase < 1000 lines: 60% coverage required.
- Codebase >= 1000 lines: 80% coverage required.
Project Architecture
The codebase follows the SOLID principles, separating concerns into distinct modules:
src/md2epub/cli.py: Handles user interaction and commands (init,compile).src/md2epub/epub_builder.py: The core logic class (EpubBuilder) responsible for assembling the book, managing metadata, and ensuring strictly ordered spine items (Cover -> Front Matter -> TOC -> Chapters).src/md2epub/converter.py: Handles text processing, converting Markdown to HTML and injecting custom classes for separators.src/md2epub/css_template.py: Contains theKDP_CSSstring used to style the EPUB.
Release Workflow
The project uses GitHub Actions for CI/CD.
-
Pull Requests: PRs to
mainmust come fromdev. -
Versioning: Semantic versioning is automated based on PR labels. When a PR is merged to
main: -
Label
bump:major→ Major increment. -
Label
bump:patch→ Patch increment. -
Default (no label/other) → Minor increment.
-
Publishing: Releases are automatically published to PyPI and GitHub Releases upon merge.
License
This project is licensed under the MIT License.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file md2epub-0.2.0.tar.gz.
File metadata
- Download URL: md2epub-0.2.0.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e273878608fbc1c7ca4d93674432bc57d43bc2f607053c781f3ca769db55178
|
|
| MD5 |
f3ae51c0495ce3be1fefbdbf170161d8
|
|
| BLAKE2b-256 |
c63d0492c82738553b2dae1e52cb05b1df3d1c3e6c1a8daa44bd6dee35150d02
|
Provenance
The following attestation bundles were made for md2epub-0.2.0.tar.gz:
Publisher:
main-release.yml on neolaw84/md2epub
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
md2epub-0.2.0.tar.gz -
Subject digest:
4e273878608fbc1c7ca4d93674432bc57d43bc2f607053c781f3ca769db55178 - Sigstore transparency entry: 871593233
- Sigstore integration time:
-
Permalink:
neolaw84/md2epub@e65be10934cec2f7230140bc3daf83e3d46ae5d3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/neolaw84
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main-release.yml@e65be10934cec2f7230140bc3daf83e3d46ae5d3 -
Trigger Event:
pull_request
-
Statement type:
File details
Details for the file md2epub-0.2.0-py3-none-any.whl.
File metadata
- Download URL: md2epub-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74f6605993d8ded161aa7dc149e5bf534fd8c22e11d60085bda2c2dd92decdc9
|
|
| MD5 |
450bdfa4f7a7638c7e71e38b8910f129
|
|
| BLAKE2b-256 |
77d04b02106f39d04172dae34a1fa0736f73e884f97cb578eac1b92868306b71
|
Provenance
The following attestation bundles were made for md2epub-0.2.0-py3-none-any.whl:
Publisher:
main-release.yml on neolaw84/md2epub
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
md2epub-0.2.0-py3-none-any.whl -
Subject digest:
74f6605993d8ded161aa7dc149e5bf534fd8c22e11d60085bda2c2dd92decdc9 - Sigstore transparency entry: 871593252
- Sigstore integration time:
-
Permalink:
neolaw84/md2epub@e65be10934cec2f7230140bc3daf83e3d46ae5d3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/neolaw84
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main-release.yml@e65be10934cec2f7230140bc3daf83e3d46ae5d3 -
Trigger Event:
pull_request
-
Statement type: