Skip to main content

A powerful text-to-EPUB conversion tool

Project description

MyEPUBApp

PyPI version Python 3.8+ License: MIT

A powerful and flexible text-to-EPUB conversion tool that transforms plain text files into standard EPUB e-book format with advanced features for content processing and validation.

โœจ Features

  • ๐Ÿ“– Text to EPUB Conversion: Convert plain text files to fully EPUB-compliant e-books
  • ๐Ÿ“‘ Intelligent Chapter Detection: Automatically identify and split chapters using special marker symbols
  • ๐ŸŽฏ Smart Volume Detection: Automatic hierarchical TOC generation based on chapter level combinations
    • Detects h1+h2 pattern and makes h1 chapters into volumes
    • Detects h2+h3 pattern and makes h2 chapters into volumes
    • Detects h1+h3 pattern and makes h1 chapters into volumes
  • ๐Ÿ”„ Flexible Operation Modes: Support for creating new EPUB files or appending chapters to existing ones
  • โœ… EPUB Validation: Built-in EPUB format validation with detailed compliance checking
  • ๐Ÿ—๏ธ Modular Architecture: Clean, maintainable code structure for easy extension
  • ๐Ÿ“ Comprehensive Logging: Detailed operation logging with configurable log levels
  • ๐ŸŽจ Cover Image Support: Add custom cover images to your EPUB files
  • ๐Ÿ“‹ Table of Contents: Automatic generation of navigation and table of contents with hierarchical structure

๐Ÿš€ Installation

Requirements

  • Python 3.8 or higher
  • pip package manager

Option 1: Install from PyPI (Recommended)

pip install myepubapp

Option 2: Install from Source

  1. Clone the repository:
git clone https://github.com/eyes1971/myepubapp.git
cd myepubapp
  1. Install dependencies:
pip install -r requirements.txt
  1. Install in development mode:
pip install -e .

๐Ÿ“– Usage

Basic Usage

1. Create New EPUB File

myepubapp -i input.txt --output-epub output.epub

Automatic Title Generation: Book titles are automatically generated from input filenames (e.g., my_book.txt becomes "My Book")

2. Append Chapters to Existing EPUB

myepubapp -a input.txt --input-epub existing.epub --output-epub updated.epub

3. Validate EPUB File

myepubapp -v --input-epub file.epub

Command Line Options

Option Short Description
--init -i Initialize mode: create new EPUB file
--append -a Append mode: add chapters to existing EPUB
--validate -v Validate EPUB file format and structure
input_file Input text file path (not required for validate mode)
--input-epub -ie Existing EPUB file (required for append/validate modes)
--output-epub -o Output EPUB file path
--convert-tags -ct Convert <> tags to Chinese book title marks ใ€Šใ€‹
--cover -c Path to cover image file

Input File Format

Text files should use special marker symbols for chapter organization:

โ€ปโ˜† Introduction Title
This is the introduction content.
It can span multiple paragraphs and will be displayed as a separate introduction page.

โ€ปโ…ฐ Chapter 1 Title
Chapter content goes here...
Multiple paragraphs are supported.

โ€ปโ…ฑ Chapter 1 Section 1
Subsection content...

โ€ปโ…ฒ Chapter 1 Section 1 Subsection 1
Deeper level content with full formatting support.

Marker Symbols:

  • โ€ปโ˜†: Introduction page (creates separate intro page)
  • โ€ปโ…ฐ: Level 1 chapter (h1 heading)
  • โ€ปโ…ฑ: Level 2 chapter (h2 heading)
  • โ€ปโ…ฒ: Level 3 chapter (h3 heading)

๐Ÿ“‹ Examples

Create Simple EPUB

myepubapp -i sample.txt --output-epub mybook.epub

Create EPUB with Chinese Tag Conversion

myepubapp -i sample.txt --output-epub mybook.epub --convert-tags

Add Cover Image

myepubapp -i sample.txt --output-epub mybook.epub --cover cover.jpg

Append Chapters to Existing EPUB

myepubapp -a chapter2.txt --input-epub mybook.epub --output-epub mybook_updated.epub

Validate EPUB File

myepubapp -v --input-epub mybook.epub

๐Ÿ—๏ธ Project Structure

myepubapp/
โ”œโ”€โ”€ core/                    # Core business logic
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ book.py             # EPUB book management
โ”‚   โ”œโ”€โ”€ chapter.py          # Chapter data structures
โ”‚   โ””โ”€โ”€ metadata.py         # EPUB metadata handling
โ”œโ”€โ”€ generators/             # Content generation modules
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ content.py          # Content processing and chapter generation
โ”‚   โ””โ”€โ”€ toc.py             # Table of contents generation
โ”œโ”€โ”€ utils/                  # Utility modules
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ epub_validator.py   # EPUB format validation
โ”‚   โ”œโ”€โ”€ file_handler.py     # File I/O operations
โ”‚   โ”œโ”€โ”€ logger.py          # Logging configuration
โ”‚   โ””โ”€โ”€ text_processor.py   # Text processing utilities
โ”œโ”€โ”€ exceptions/             # Custom exception classes
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ epub_exceptions.py  # EPUB-specific exceptions
โ”œโ”€โ”€ cli.py                 # Command-line interface
โ”œโ”€โ”€ __init__.py            # Package initialization
โ””โ”€โ”€ py.typed               # Type hints marker

๐Ÿ“‹ Dependencies

  • ebooklib>=0.18.0: Core EPUB file processing and manipulation
  • beautifulsoup4>=4.12.0: HTML/XML parsing and manipulation

๐Ÿ” Validation Features

The built-in EPUB validator checks:

  • โœ… File structure compliance
  • โœ… Required metadata presence
  • โœ… MIME type validation
  • โœ… Container XML format
  • โœ… Content OPF validation
  • โœ… Spine and manifest integrity
  • โœ… XHTML content validation

๐Ÿ“ Logging

All operations are logged with configurable verbosity. Logs are written to:

  • Console output (with appropriate log levels)
  • logs/myepubapp.log file (detailed operation logs)

๐Ÿค Contributing

We welcome contributions! Please feel free to:

  1. Report bugs via GitHub Issues
  2. Submit feature requests
  3. Create pull requests with improvements

Development Setup

  1. Fork the repository
  2. Clone your fork: git clone https://github.com/yourusername/myepubapp.git
  3. Create a virtual environment: python -m venv venv
  4. Activate the environment: source venv/bin/activate (Linux/Mac) or venv\Scripts\activate (Windows)
  5. Install development dependencies: pip install -r requirements.txt
  6. Install in development mode: pip install -e .
  7. Run tests: python -m pytest

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Built with ebooklib for EPUB processing
  • Uses Beautiful Soup for HTML parsing
  • Inspired by the need for simple, reliable text-to-EPUB conversion tools

๐Ÿ“ž Support

If you encounter any issues or have questions:

  • Check the Issues page
  • Create a new issue with detailed information
  • Include sample input files and error messages when reporting bugs

๐Ÿ“‹ Changelog

Version 1.0.4 (2025-09-08)

  • โœจ Added Smart Volume Detection: Automatic hierarchical TOC generation based on chapter level combinations
    • Detects h1+h2 pattern and makes h1 chapters into volumes
    • Detects h2+h3 pattern and makes h2 chapters into volumes
    • Detects h1+h3 pattern and makes h1 chapters into volumes
  • ๐ŸŽฏ Added Intelligent TOC Structure: Creates nested table of contents for multi-volume books
  • ๐Ÿ“– Enhanced Chapter Processing: Improved chapter ordering and Introduction page positioning
  • ๐Ÿ› Fixed Critical EPUB Generation Errors: Resolved multiple epubcheck validation failures
    • Fixed duplicate cover image entries in manifest
    • Fixed undefined cover property errors
    • Fixed duplicate "cover" IDs causing OPF validation errors
  • ๐Ÿ”ง Fixed TOC Reading Order Issues: Fixed NAV-011 warnings about TOC link order mismatch
    • TOC links now match spine reading order
    • Proper EPUB 3.0 compliance for navigation structure
  • ๐Ÿ“‹ Fixed Cover Image Handling: Resolved cover image declaration and property issues
    • Fixed RSC-008 error: Referenced resource not declared in OPF manifest
    • Fixed OPF-027 error: Undefined property "cover"
    • Fixed RSC-005 error: Duplicate entries in ZIP file
  • ๐Ÿ“– Fixed Introduction Page Ordering: Fixed Introduction page appearing at the end instead of beginning
    • Proper spine ordering: nav โ†’ intro โ†’ chapters
    • Correct TOC positioning for introduction content
  • โœ… Enhanced EPUB 3.0 Compliance: All generated EPUB files now pass epubcheck validation

Version 1.0.3 (2025-09-08)

  • This update primarily focuses on optimizing the core src/myepubapp/core/book.py module:
  • Updated function documentation: _extract_chapters_from_epub() and merge_existing_epub_with_new_chapters()
  • Updated log outputs: EPUB merge success and error messages
  • Maintained functionality integrity: All changes are non-breaking, preserving all functional logic

Version 1.0.2 (2025-09-05)

  • ๐Ÿ› Fixed: Critical TOC generation bug causing missing chapters in table of contents
  • ๐Ÿ› Fixed: TOC only showing first few chapters, skipping subsequent ones in multi-chapter documents
  • ๐Ÿ”ง Improved: TOC generator recursive logic now properly handles chapter indexing after processing child elements
  • ๐Ÿ”ง Improved: Fixed index management in build_toc_level() function to prevent chapter skipping
  • โœ… Enhanced: TOC generation now works correctly for any number of chapters and all hierarchy levels

Version 1.0.1 (2025-09-05)

  • ๐Ÿ› Fixed: EPUB TOC generation error when using h2/h3 chapter levels
  • ๏ฟฝ Fixed: Empty <ol> elements in nav.xhtml causing epubcheck validation failures
  • ๐Ÿ”ง Improved: TOC generator now properly handles all chapter level combinations (h1, h2, h3)
  • ๐Ÿ”ง Improved: Automatic level detection for chapters with skipped levels (e.g., intro โ†’ h2)
  • โœ… Enhanced: EPUB validation compliance for all supported chapter structures

Version 1.0.0 (2025-09-01)

  • โœจ Initial release with full text-to-EPUB conversion functionality
  • ๏ฟฝ๐Ÿ“– Support for Chinese content with automatic title mark conversion
  • ๐Ÿ“‘ Intelligent chapter detection using marker symbols
  • ๐Ÿ”„ Flexible operation modes (create new EPUB or append chapters)
  • โœ… Built-in EPUB validation with detailed compliance checking
  • ๐ŸŽจ Cover image support
  • ๐Ÿ“‹ Automatic table of contents generation

Version: 1.0.4 Author: Sam Weng Repository: https://github.com/eyes1971/myepubapp

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

myepubapp-1.0.7.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

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

myepubapp-1.0.7-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

Details for the file myepubapp-1.0.7.tar.gz.

File metadata

  • Download URL: myepubapp-1.0.7.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for myepubapp-1.0.7.tar.gz
Algorithm Hash digest
SHA256 b8de0b7643dec21eba76f17dc996f66af0686c1afef92666b57775d8cfc4f205
MD5 394741d38ede91fdba53741d4ffb9a8b
BLAKE2b-256 c6568c442285450e7adc67361c7e48b9a8aed6e3fa1f930d4564415fcd78705d

See more details on using hashes here.

File details

Details for the file myepubapp-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: myepubapp-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 24.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for myepubapp-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 b9e114dc5946979a6ef60d6023805395dd510b20661370bf42f83f881251439b
MD5 47794dd6a2a7e958ccc1c6e45153d532
BLAKE2b-256 5e9fdf42c9a06ed7adc6e6367b5657551e03eb7aed3b990721f42d2df39dc45d

See more details on using hashes here.

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