epub-generator 0.1.3__tar.gz → 0.1.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {epub_generator-0.1.3 → epub_generator-0.1.4}/PKG-INFO +19 -15
- {epub_generator-0.1.3 → epub_generator-0.1.4}/README.md +18 -14
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/generation/gen_chapter.py +6 -3
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/types.py +2 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/pyproject.toml +1 -1
- {epub_generator-0.1.3 → epub_generator-0.1.4}/LICENSE +0 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/__init__.py +0 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/context.py +0 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/data/container.xml.jinja +0 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/data/content.opf.jinja +0 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/data/cover.xhtml.jinja +0 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/data/mimetype.jinja +0 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/data/nav.xhtml.jinja +0 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/data/part.xhtml.jinja +0 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/data/style.css.jinja +0 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/generation/__init__.py +0 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/generation/gen_asset.py +0 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/generation/gen_epub.py +0 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/generation/gen_nav.py +0 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/generation/gen_toc.py +0 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/generation/xml_utils.py +0 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/html_tag.py +0 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/i18n.py +0 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/options.py +0 -0
- {epub_generator-0.1.3 → epub_generator-0.1.4}/epub_generator/template.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: epub-generator
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: A simple Python EPUB 3.0 generator with a single API call
|
|
5
5
|
License: MIT
|
|
6
6
|
Keywords: epub,epub3,ebook,generator,publishing
|
|
@@ -61,9 +61,9 @@ epub_data = EpubData(
|
|
|
61
61
|
title="Chapter 1",
|
|
62
62
|
get_chapter=lambda: Chapter(
|
|
63
63
|
elements=[
|
|
64
|
-
TextBlock(kind=TextKind.HEADLINE, content=["Chapter 1"]),
|
|
65
|
-
TextBlock(kind=TextKind.BODY, content=["This is the first paragraph."]),
|
|
66
|
-
TextBlock(kind=TextKind.BODY, content=["This is the second paragraph."]),
|
|
64
|
+
TextBlock(kind=TextKind.HEADLINE, level=0, content=["Chapter 1"]),
|
|
65
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["This is the first paragraph."]),
|
|
66
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["This is the second paragraph."]),
|
|
67
67
|
]
|
|
68
68
|
),
|
|
69
69
|
),
|
|
@@ -111,8 +111,8 @@ epub_data = EpubData(
|
|
|
111
111
|
title="Chapter 1",
|
|
112
112
|
get_chapter=lambda: Chapter(
|
|
113
113
|
elements=[
|
|
114
|
-
TextBlock(kind=TextKind.HEADLINE, content=["Chapter 1"]),
|
|
115
|
-
TextBlock(kind=TextKind.BODY, content=["Main content..."]),
|
|
114
|
+
TextBlock(kind=TextKind.HEADLINE, level=0, content=["Chapter 1"]),
|
|
115
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["Main content..."]),
|
|
116
116
|
]
|
|
117
117
|
),
|
|
118
118
|
),
|
|
@@ -136,7 +136,7 @@ epub_data = EpubData(
|
|
|
136
136
|
title="Chapter 1.1",
|
|
137
137
|
get_chapter=lambda: Chapter(
|
|
138
138
|
elements=[
|
|
139
|
-
TextBlock(kind=TextKind.BODY, content=["Content 1.1..."]),
|
|
139
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["Content 1.1..."]),
|
|
140
140
|
]
|
|
141
141
|
),
|
|
142
142
|
),
|
|
@@ -144,7 +144,7 @@ epub_data = EpubData(
|
|
|
144
144
|
title="Chapter 1.2",
|
|
145
145
|
get_chapter=lambda: Chapter(
|
|
146
146
|
elements=[
|
|
147
|
-
TextBlock(kind=TextKind.BODY, content=["Content 1.2..."]),
|
|
147
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["Content 1.2..."]),
|
|
148
148
|
]
|
|
149
149
|
),
|
|
150
150
|
),
|
|
@@ -168,7 +168,7 @@ epub_data = EpubData(
|
|
|
168
168
|
title="Chapter 1",
|
|
169
169
|
get_chapter=lambda: Chapter(
|
|
170
170
|
elements=[
|
|
171
|
-
TextBlock(kind=TextKind.BODY, content=["Here's an image:"]),
|
|
171
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["Here's an image:"]),
|
|
172
172
|
Image(
|
|
173
173
|
path=Path("image.png"), # Image path
|
|
174
174
|
alt_text="Image description",
|
|
@@ -195,6 +195,7 @@ epub_data = EpubData(
|
|
|
195
195
|
elements=[
|
|
196
196
|
TextBlock(
|
|
197
197
|
kind=TextKind.BODY,
|
|
198
|
+
level=0,
|
|
198
199
|
content=[
|
|
199
200
|
"This is text with a footnote",
|
|
200
201
|
Mark(id=1), # Footnote marker
|
|
@@ -206,7 +207,7 @@ epub_data = EpubData(
|
|
|
206
207
|
Footnote(
|
|
207
208
|
id=1,
|
|
208
209
|
contents=[
|
|
209
|
-
TextBlock(kind=TextKind.BODY, content=["This is the footnote content."]),
|
|
210
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["This is the footnote content."]),
|
|
210
211
|
],
|
|
211
212
|
),
|
|
212
213
|
],
|
|
@@ -229,7 +230,7 @@ epub_data = EpubData(
|
|
|
229
230
|
title="Chapter 1",
|
|
230
231
|
get_chapter=lambda: Chapter(
|
|
231
232
|
elements=[
|
|
232
|
-
TextBlock(kind=TextKind.BODY, content=["Here's a table:"]),
|
|
233
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["Here's a table:"]),
|
|
233
234
|
Table(
|
|
234
235
|
html_content="""
|
|
235
236
|
<table>
|
|
@@ -261,7 +262,7 @@ epub_data = EpubData(
|
|
|
261
262
|
title="Chapter 1",
|
|
262
263
|
get_chapter=lambda: Chapter(
|
|
263
264
|
elements=[
|
|
264
|
-
TextBlock(kind=TextKind.BODY, content=["Pythagorean theorem:"]),
|
|
265
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["Pythagorean theorem:"]),
|
|
265
266
|
Formula(latex_expression="x^2 + y^2 = z^2"), # Block-level formula
|
|
266
267
|
]
|
|
267
268
|
),
|
|
@@ -284,6 +285,7 @@ epub_data = EpubData(
|
|
|
284
285
|
elements=[
|
|
285
286
|
TextBlock(
|
|
286
287
|
kind=TextKind.BODY,
|
|
288
|
+
level=0,
|
|
287
289
|
content=[
|
|
288
290
|
"The Pythagorean theorem ",
|
|
289
291
|
Formula(latex_expression="a^2 + b^2 = c^2"), # Inline formula
|
|
@@ -314,6 +316,7 @@ epub_data = EpubData(
|
|
|
314
316
|
title="Chapter 1",
|
|
315
317
|
get_chapter=lambda: Chapter(elements=[TextBlock(
|
|
316
318
|
kind=TextKind.BODY,
|
|
319
|
+
level=0,
|
|
317
320
|
content=[
|
|
318
321
|
"This is normal text with ",
|
|
319
322
|
HTMLTag(
|
|
@@ -348,8 +351,8 @@ epub_data = EpubData(
|
|
|
348
351
|
title="Preface",
|
|
349
352
|
get_chapter=lambda: Chapter(
|
|
350
353
|
elements=[
|
|
351
|
-
TextBlock(kind=TextKind.HEADLINE, content=["Preface"]),
|
|
352
|
-
TextBlock(kind=TextKind.BODY, content=["This is the preface content..."]),
|
|
354
|
+
TextBlock(kind=TextKind.HEADLINE, level=0, content=["Preface"]),
|
|
355
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["This is the preface content..."]),
|
|
353
356
|
]
|
|
354
357
|
),
|
|
355
358
|
),
|
|
@@ -359,7 +362,7 @@ epub_data = EpubData(
|
|
|
359
362
|
title="Chapter 1",
|
|
360
363
|
get_chapter=lambda: Chapter(
|
|
361
364
|
elements=[
|
|
362
|
-
TextBlock(kind=TextKind.BODY, content=["Main content..."]),
|
|
365
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["Main content..."]),
|
|
363
366
|
]
|
|
364
367
|
),
|
|
365
368
|
),
|
|
@@ -457,6 +460,7 @@ class Chapter:
|
|
|
457
460
|
@dataclass
|
|
458
461
|
class TextBlock:
|
|
459
462
|
kind: TextKind # BODY | HEADLINE | QUOTE
|
|
463
|
+
level: int # Heading level (0→h1, 1→h2, max h6; only for HEADLINE)
|
|
460
464
|
content: list[str | Mark | Formula | HTMLTag] # Text with optional marks, inline formulas, and HTML tags
|
|
461
465
|
```
|
|
462
466
|
|
|
@@ -34,9 +34,9 @@ epub_data = EpubData(
|
|
|
34
34
|
title="Chapter 1",
|
|
35
35
|
get_chapter=lambda: Chapter(
|
|
36
36
|
elements=[
|
|
37
|
-
TextBlock(kind=TextKind.HEADLINE, content=["Chapter 1"]),
|
|
38
|
-
TextBlock(kind=TextKind.BODY, content=["This is the first paragraph."]),
|
|
39
|
-
TextBlock(kind=TextKind.BODY, content=["This is the second paragraph."]),
|
|
37
|
+
TextBlock(kind=TextKind.HEADLINE, level=0, content=["Chapter 1"]),
|
|
38
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["This is the first paragraph."]),
|
|
39
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["This is the second paragraph."]),
|
|
40
40
|
]
|
|
41
41
|
),
|
|
42
42
|
),
|
|
@@ -84,8 +84,8 @@ epub_data = EpubData(
|
|
|
84
84
|
title="Chapter 1",
|
|
85
85
|
get_chapter=lambda: Chapter(
|
|
86
86
|
elements=[
|
|
87
|
-
TextBlock(kind=TextKind.HEADLINE, content=["Chapter 1"]),
|
|
88
|
-
TextBlock(kind=TextKind.BODY, content=["Main content..."]),
|
|
87
|
+
TextBlock(kind=TextKind.HEADLINE, level=0, content=["Chapter 1"]),
|
|
88
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["Main content..."]),
|
|
89
89
|
]
|
|
90
90
|
),
|
|
91
91
|
),
|
|
@@ -109,7 +109,7 @@ epub_data = EpubData(
|
|
|
109
109
|
title="Chapter 1.1",
|
|
110
110
|
get_chapter=lambda: Chapter(
|
|
111
111
|
elements=[
|
|
112
|
-
TextBlock(kind=TextKind.BODY, content=["Content 1.1..."]),
|
|
112
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["Content 1.1..."]),
|
|
113
113
|
]
|
|
114
114
|
),
|
|
115
115
|
),
|
|
@@ -117,7 +117,7 @@ epub_data = EpubData(
|
|
|
117
117
|
title="Chapter 1.2",
|
|
118
118
|
get_chapter=lambda: Chapter(
|
|
119
119
|
elements=[
|
|
120
|
-
TextBlock(kind=TextKind.BODY, content=["Content 1.2..."]),
|
|
120
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["Content 1.2..."]),
|
|
121
121
|
]
|
|
122
122
|
),
|
|
123
123
|
),
|
|
@@ -141,7 +141,7 @@ epub_data = EpubData(
|
|
|
141
141
|
title="Chapter 1",
|
|
142
142
|
get_chapter=lambda: Chapter(
|
|
143
143
|
elements=[
|
|
144
|
-
TextBlock(kind=TextKind.BODY, content=["Here's an image:"]),
|
|
144
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["Here's an image:"]),
|
|
145
145
|
Image(
|
|
146
146
|
path=Path("image.png"), # Image path
|
|
147
147
|
alt_text="Image description",
|
|
@@ -168,6 +168,7 @@ epub_data = EpubData(
|
|
|
168
168
|
elements=[
|
|
169
169
|
TextBlock(
|
|
170
170
|
kind=TextKind.BODY,
|
|
171
|
+
level=0,
|
|
171
172
|
content=[
|
|
172
173
|
"This is text with a footnote",
|
|
173
174
|
Mark(id=1), # Footnote marker
|
|
@@ -179,7 +180,7 @@ epub_data = EpubData(
|
|
|
179
180
|
Footnote(
|
|
180
181
|
id=1,
|
|
181
182
|
contents=[
|
|
182
|
-
TextBlock(kind=TextKind.BODY, content=["This is the footnote content."]),
|
|
183
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["This is the footnote content."]),
|
|
183
184
|
],
|
|
184
185
|
),
|
|
185
186
|
],
|
|
@@ -202,7 +203,7 @@ epub_data = EpubData(
|
|
|
202
203
|
title="Chapter 1",
|
|
203
204
|
get_chapter=lambda: Chapter(
|
|
204
205
|
elements=[
|
|
205
|
-
TextBlock(kind=TextKind.BODY, content=["Here's a table:"]),
|
|
206
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["Here's a table:"]),
|
|
206
207
|
Table(
|
|
207
208
|
html_content="""
|
|
208
209
|
<table>
|
|
@@ -234,7 +235,7 @@ epub_data = EpubData(
|
|
|
234
235
|
title="Chapter 1",
|
|
235
236
|
get_chapter=lambda: Chapter(
|
|
236
237
|
elements=[
|
|
237
|
-
TextBlock(kind=TextKind.BODY, content=["Pythagorean theorem:"]),
|
|
238
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["Pythagorean theorem:"]),
|
|
238
239
|
Formula(latex_expression="x^2 + y^2 = z^2"), # Block-level formula
|
|
239
240
|
]
|
|
240
241
|
),
|
|
@@ -257,6 +258,7 @@ epub_data = EpubData(
|
|
|
257
258
|
elements=[
|
|
258
259
|
TextBlock(
|
|
259
260
|
kind=TextKind.BODY,
|
|
261
|
+
level=0,
|
|
260
262
|
content=[
|
|
261
263
|
"The Pythagorean theorem ",
|
|
262
264
|
Formula(latex_expression="a^2 + b^2 = c^2"), # Inline formula
|
|
@@ -287,6 +289,7 @@ epub_data = EpubData(
|
|
|
287
289
|
title="Chapter 1",
|
|
288
290
|
get_chapter=lambda: Chapter(elements=[TextBlock(
|
|
289
291
|
kind=TextKind.BODY,
|
|
292
|
+
level=0,
|
|
290
293
|
content=[
|
|
291
294
|
"This is normal text with ",
|
|
292
295
|
HTMLTag(
|
|
@@ -321,8 +324,8 @@ epub_data = EpubData(
|
|
|
321
324
|
title="Preface",
|
|
322
325
|
get_chapter=lambda: Chapter(
|
|
323
326
|
elements=[
|
|
324
|
-
TextBlock(kind=TextKind.HEADLINE, content=["Preface"]),
|
|
325
|
-
TextBlock(kind=TextKind.BODY, content=["This is the preface content..."]),
|
|
327
|
+
TextBlock(kind=TextKind.HEADLINE, level=0, content=["Preface"]),
|
|
328
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["This is the preface content..."]),
|
|
326
329
|
]
|
|
327
330
|
),
|
|
328
331
|
),
|
|
@@ -332,7 +335,7 @@ epub_data = EpubData(
|
|
|
332
335
|
title="Chapter 1",
|
|
333
336
|
get_chapter=lambda: Chapter(
|
|
334
337
|
elements=[
|
|
335
|
-
TextBlock(kind=TextKind.BODY, content=["Main content..."]),
|
|
338
|
+
TextBlock(kind=TextKind.BODY, level=0, content=["Main content..."]),
|
|
336
339
|
]
|
|
337
340
|
),
|
|
338
341
|
),
|
|
@@ -430,6 +433,7 @@ class Chapter:
|
|
|
430
433
|
@dataclass
|
|
431
434
|
class TextBlock:
|
|
432
435
|
kind: TextKind # BODY | HEADLINE | QUOTE
|
|
436
|
+
level: int # Heading level (0→h1, 1→h2, max h6; only for HEADLINE)
|
|
433
437
|
content: list[str | Mark | Formula | HTMLTag] # Text with optional marks, inline formulas, and HTML tags
|
|
434
438
|
```
|
|
435
439
|
|
|
@@ -17,6 +17,8 @@ from ..types import (
|
|
|
17
17
|
from .gen_asset import process_formula, process_image, process_table
|
|
18
18
|
from .xml_utils import serialize_element, set_epub_type
|
|
19
19
|
|
|
20
|
+
_MAX_HEADING_LEVEL = 6 # HTML standard defines heading levels from h1 to h6
|
|
21
|
+
|
|
20
22
|
|
|
21
23
|
def generate_chapter(
|
|
22
24
|
context: Context,
|
|
@@ -91,7 +93,8 @@ def _render_footnotes(
|
|
|
91
93
|
def _render_content_block(context: Context, block: ContentBlock) -> Element | None:
|
|
92
94
|
if isinstance(block, TextBlock):
|
|
93
95
|
if block.kind == TextKind.HEADLINE:
|
|
94
|
-
|
|
96
|
+
heading_level = min(block.level + 1, _MAX_HEADING_LEVEL)
|
|
97
|
+
container = Element(f"h{heading_level}")
|
|
95
98
|
elif block.kind == TextKind.QUOTE:
|
|
96
99
|
container = Element("p")
|
|
97
100
|
elif block.kind == TextKind.BODY:
|
|
@@ -100,8 +103,8 @@ def _render_content_block(context: Context, block: ContentBlock) -> Element | No
|
|
|
100
103
|
raise ValueError(f"Unknown TextKind: {block.kind}")
|
|
101
104
|
|
|
102
105
|
_render_text_content(
|
|
103
|
-
context=context,
|
|
104
|
-
parent=container,
|
|
106
|
+
context=context,
|
|
107
|
+
parent=container,
|
|
105
108
|
content=block.content,
|
|
106
109
|
)
|
|
107
110
|
if block.kind == TextKind.QUOTE:
|
|
@@ -110,6 +110,8 @@ class Image:
|
|
|
110
110
|
class TextBlock:
|
|
111
111
|
kind: TextKind
|
|
112
112
|
"""Kind of text block."""
|
|
113
|
+
level: int
|
|
114
|
+
"""Heading level starting from 0 (only for HEADLINE: level 0 → h1, level 1 → h2, max h6; ignored for BODY and QUOTE)."""
|
|
113
115
|
content: list["str | Mark | Formula | HTMLTag"]
|
|
114
116
|
"""Text content with optional citation marks."""
|
|
115
117
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|