epub-generator 0.1.3__py3-none-any.whl → 0.1.4__py3-none-any.whl
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/generation/gen_chapter.py +6 -3
- epub_generator/types.py +2 -0
- {epub_generator-0.1.3.dist-info → epub_generator-0.1.4.dist-info}/METADATA +19 -15
- {epub_generator-0.1.3.dist-info → epub_generator-0.1.4.dist-info}/RECORD +6 -6
- {epub_generator-0.1.3.dist-info → epub_generator-0.1.4.dist-info}/LICENSE +0 -0
- {epub_generator-0.1.3.dist-info → epub_generator-0.1.4.dist-info}/WHEEL +0 -0
|
@@ -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:
|
epub_generator/types.py
CHANGED
|
@@ -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
|
|
|
@@ -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
|
|
|
@@ -9,7 +9,7 @@ epub_generator/data/part.xhtml.jinja,sha256=FEQaUjHfCy7EJyyvYZj-6T-lkDcsmz1wvsk0
|
|
|
9
9
|
epub_generator/data/style.css.jinja,sha256=HyGWoevaZD9xPDJeMQY_1xmM0f6aK0prmqoW3mhTGp0,1072
|
|
10
10
|
epub_generator/generation/__init__.py,sha256=UIscwHa8ocr2D1mk1KaP-zi3P1x9eYJzxTo0RJ2dnks,35
|
|
11
11
|
epub_generator/generation/gen_asset.py,sha256=0muwCvAohODC76F9G9_UBibRPQSpmMJkgQxlCsM7QcQ,4480
|
|
12
|
-
epub_generator/generation/gen_chapter.py,sha256=
|
|
12
|
+
epub_generator/generation/gen_chapter.py,sha256=Irb0uJjK8Q5PnHoK4PFP7CIKKzbfhIK_4thvin6hg6g,5505
|
|
13
13
|
epub_generator/generation/gen_epub.py,sha256=zkG0U5_g3FY-D6zkYGqp844IgWYJhbAqf6CnX2Do71Y,6412
|
|
14
14
|
epub_generator/generation/gen_nav.py,sha256=D-ZNsbm26AEAovbXtx1wSwTfH4Q8H2WYfoYeQ1Sb9bk,2813
|
|
15
15
|
epub_generator/generation/gen_toc.py,sha256=yt7GYu8Rfz9aw_GPZFUl9H3BKd1za1hSm2hhp8wyI68,2488
|
|
@@ -18,8 +18,8 @@ epub_generator/html_tag.py,sha256=P_Y0uRStCEEh7cCtpvK4t432NEcY9OLntAznvdxUF5k,34
|
|
|
18
18
|
epub_generator/i18n.py,sha256=GQjpHO7t8_0rXNuoYmO-G7_9nCF7S5kluBG0ip_2jIA,622
|
|
19
19
|
epub_generator/options.py,sha256=Er1dnaNvzDSnZRSRJGSqhkJsv1XtsCW2Ym_hUc8o_QI,181
|
|
20
20
|
epub_generator/template.py,sha256=RdN2QRICIrYMzpxCU_x4m4V9WWZEP9VvT6QLp2YCm90,1556
|
|
21
|
-
epub_generator/types.py,sha256=
|
|
22
|
-
epub_generator-0.1.
|
|
23
|
-
epub_generator-0.1.
|
|
24
|
-
epub_generator-0.1.
|
|
25
|
-
epub_generator-0.1.
|
|
21
|
+
epub_generator/types.py,sha256=Raz6MT-aIkMp6Yw9hTu4HP_ySg4kMC-YJ_o0cjYzu_A,4059
|
|
22
|
+
epub_generator-0.1.4.dist-info/LICENSE,sha256=9Zt_a4mrzkvR2rc0UbqTgbboIjWuumDFgeQyKos0H2E,1066
|
|
23
|
+
epub_generator-0.1.4.dist-info/METADATA,sha256=cpydosW4bVyknIbCxKP4DAhl-M8NSct7-9jX9M4BISw,16555
|
|
24
|
+
epub_generator-0.1.4.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
25
|
+
epub_generator-0.1.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|