semvec/pypi-packages huggingface dataset:
simplest-epub-generator 0.1.4
A simplest EPUB file generator with image support.
Requires Python: >=3.8

# EPUB Generator

**EPUB Generator** is a simplest Python library for creating EPUB e-books with support for images and HTML content.

---

## Table of Contents

- [Installation](#installation)
- [Examples](#examples)
- [API](#api)
- [License](#license)

---

## Installation

Install the library with pip:

```bash
pip install simplest_epub_generator
```

---

## Examples

### Example 1: Creating a book with plain text and images

```python
from pathlib import Path
from simplest_epub_generator import Chapter, Epub


chapter1 = Chapter(
    title="Chapter 1",
    text="This is the text of the first chapter. \nNew paragraph."
)

chapter2 = Chapter(
    title="Chapter 2",
    text="This is the text of the second chapter. <img src='./images/example.jpg' />"
)

book = Epub(book_name="Simple Book", author="Author")
book.add_chapters([chapter1, chapter2])
book.write_file(Path("./simple_book.epub"))
```

### Example 2: Creating a book with HTML content and images

```python
from pathlib import Path
from simplest_epub_generator import Chapter, Epub


chapter1 = Chapter(
    title="<h1>HTML Chapter</h1>",
    text="<p>Text with <strong>HTML</strong>.</p><img src='./images/example.jpg' />",
    is_html=True
)

book = Epub(book_name="HTML Book", author="Author")
book.add_chapter(chapter1)
book.write_file(Path("./html_book.epub"))
```

---

## API

### `Chapter` Class

A class representing a chapter in an EPUB book.

#### Constructor parameters

- `title (str)`: Title of the chapter.
- `text (str)`: Text content of the chapter.
- `is_html (bool, optional)`: Flag indicating if `title` and `text` contain HTML markup. Defaults to `False`.
- `lang (str, optional)`: Language of the chapter. Defaults to `"eng"`.

#### Class attributes

- `self.title (str)`: Title of the chapter.
- `self.html_content (str)`: A variable containing the title and text in HTML format.
- `self.lang (str)`: Language of the chapter.

#### Methods

- `remove_tags(html: str) -> str`: Removes HTML tags from a string.
- `get_image_paths() -> Set[str]`: Extracts image paths from the chapter's HTML content.

---

### `Epub` Class

A class for creating and managing an EPUB book.

#### Constructor parameters

- `book_name (str)`: Name of the book.
- `lang (str, optional)`: Language of the book. Defaults to `"eng"`.
- `author (str, optional)`: Author of the book. Defaults to an empty string.

#### Class attributes

- `self.book_name (str)`: Name of the book.
- `self.lang (str)`: Language of the book.
- `self.author (str)`: Author of the book.

#### Methods

- `add_chapter(chapter: Chapter)`: Adds a chapter to the book.
- `add_chapters(chapters: List[Chapter])`: Adds multiple chapters to the book.
- `write_file(path: Path)`: Saves the book to a file at the specified path.

---

## License

This project is licensed under the MIT License. See the [LICENSE](https://github.com/rrfedorovich/simplest_epub_generator/blob/master/LICENSE) file for details.