txt2ebook 0.1.130__py3-none-any.whl → 0.1.132__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.
- txt2ebook/__init__.py +7 -3
- txt2ebook/cli.py +3 -1
- txt2ebook/formats/gmi.py +3 -3
- txt2ebook/parser.py +7 -6
- txt2ebook/subcommands/env.py +2 -2
- txt2ebook/subcommands/gmi.py +1 -1
- {txt2ebook-0.1.130.dist-info → txt2ebook-0.1.132.dist-info}/METADATA +1 -1
- {txt2ebook-0.1.130.dist-info → txt2ebook-0.1.132.dist-info}/RECORD +11 -11
- {txt2ebook-0.1.130.dist-info → txt2ebook-0.1.132.dist-info}/LICENSE.md +0 -0
- {txt2ebook-0.1.130.dist-info → txt2ebook-0.1.132.dist-info}/WHEEL +0 -0
- {txt2ebook-0.1.130.dist-info → txt2ebook-0.1.132.dist-info}/entry_points.txt +0 -0
txt2ebook/__init__.py
CHANGED
@@ -18,6 +18,7 @@
|
|
18
18
|
import argparse
|
19
19
|
import logging
|
20
20
|
import platform
|
21
|
+
from typing import Optional
|
21
22
|
import sys
|
22
23
|
|
23
24
|
import langdetect
|
@@ -58,9 +59,9 @@ def log_or_raise_on_warning(message: str, raise_on_warning: bool = False) -> Non
|
|
58
59
|
raise_on_warning: If True, raises a RuntimeError instead of logging.
|
59
60
|
"""
|
60
61
|
if raise_on_warning:
|
61
|
-
raise RuntimeError(
|
62
|
+
raise RuntimeError(message)
|
62
63
|
|
63
|
-
logger.warning(
|
64
|
+
logger.warning(message)
|
64
65
|
|
65
66
|
|
66
67
|
def print_env() -> None:
|
@@ -77,12 +78,15 @@ def print_env() -> None:
|
|
77
78
|
def detect_and_expect_language(content: str, config_language: str) -> str:
|
78
79
|
"""Detects the content language and compares it to the configured language.
|
79
80
|
|
81
|
+
If no config_language is provided, the detected language is used.
|
82
|
+
|
80
83
|
Args:
|
81
84
|
content: The text content to analyze.
|
82
85
|
config_language: The language specified in the configuration.
|
83
86
|
|
84
87
|
Returns:
|
85
|
-
The configured language, or the detected language if none is
|
88
|
+
The configured language, or the detected language if none is
|
89
|
+
configured.
|
86
90
|
"""
|
87
91
|
detect_language = langdetect.detect(content)
|
88
92
|
config_language = config_language or detect_language
|
txt2ebook/cli.py
CHANGED
@@ -30,6 +30,8 @@ from txt2ebook import __version__, setup_logger
|
|
30
30
|
|
31
31
|
logger = logging.getLogger(__name__)
|
32
32
|
|
33
|
+
DEFAULT_OUTPUT_FOLDER = "output"
|
34
|
+
|
33
35
|
|
34
36
|
def build_parser(
|
35
37
|
_args: Optional[Sequence[str]] = None,
|
@@ -48,7 +50,7 @@ def build_parser(
|
|
48
50
|
"-of",
|
49
51
|
"--output-folder",
|
50
52
|
dest="output_folder",
|
51
|
-
default=
|
53
|
+
default=DEFAULT_OUTPUT_FOLDER,
|
52
54
|
help="set default output folder (default: '%(default)s')",
|
53
55
|
)
|
54
56
|
|
txt2ebook/formats/gmi.py
CHANGED
@@ -84,7 +84,7 @@ class GmiWriter(BaseWriter):
|
|
84
84
|
f"_{txt_filename.stem}"
|
85
85
|
f"_{section.title}"
|
86
86
|
f"_{chapter.title}"
|
87
|
-
".
|
87
|
+
".gmi"
|
88
88
|
)
|
89
89
|
)
|
90
90
|
|
@@ -128,12 +128,12 @@ class GmiWriter(BaseWriter):
|
|
128
128
|
|
129
129
|
with open(new_filename, "w", encoding="utf8") as file:
|
130
130
|
logger.info("Generate GemText file: %s", new_filename.resolve())
|
131
|
-
file.write(self.
|
131
|
+
file.write(self._to_gmi())
|
132
132
|
|
133
133
|
if self.config.open:
|
134
134
|
self._open_file(new_filename)
|
135
135
|
|
136
|
-
def
|
136
|
+
def _to_gmi(self) -> str:
|
137
137
|
toc = self._to_toc("*", "# ") if self.config.with_toc else ""
|
138
138
|
return self._to_metadata_txt() + toc + self._to_body_txt()
|
139
139
|
|
txt2ebook/parser.py
CHANGED
@@ -88,10 +88,10 @@ class Parser:
|
|
88
88
|
Returns:
|
89
89
|
str: The formatted section header.
|
90
90
|
"""
|
91
|
-
if
|
91
|
+
if not getattr(self.config, "header_number", False) or self.config.language not in (
|
92
92
|
"zh-cn",
|
93
93
|
"zh-tw",
|
94
|
-
)
|
94
|
+
):
|
95
95
|
return words
|
96
96
|
|
97
97
|
# left pad the section number if found as halfwidth integer
|
@@ -209,11 +209,12 @@ class Parser:
|
|
209
209
|
toc.append(current_chapter)
|
210
210
|
|
211
211
|
if token.type == "PARAGRAPH":
|
212
|
-
if toc
|
213
|
-
toc[-1]
|
212
|
+
if toc:
|
213
|
+
if isinstance(toc[-1], Volume):
|
214
|
+
toc[-1].chapters[-1].add_paragraph(token.value)
|
214
215
|
|
215
|
-
|
216
|
-
|
216
|
+
if isinstance(toc[-1], Chapter):
|
217
|
+
toc[-1].add_paragraph(token.value)
|
217
218
|
|
218
219
|
# Use authors if set explicitly from command line.
|
219
220
|
if hasattr(self.config, "author") and self.config.author:
|
txt2ebook/subcommands/env.py
CHANGED
@@ -35,10 +35,10 @@ def build_subparser(subparsers) -> None:
|
|
35
35
|
|
36
36
|
|
37
37
|
def run(_args: argparse.Namespace) -> None:
|
38
|
-
"""Run env subcommand.
|
38
|
+
"""Run the env subcommand to print environment information.
|
39
39
|
|
40
40
|
Args:
|
41
|
-
|
41
|
+
_args (argparse.Namespace): Config from command line arguments (unused).
|
42
42
|
|
43
43
|
Returns:
|
44
44
|
None
|
txt2ebook/subcommands/gmi.py
CHANGED
@@ -29,7 +29,7 @@ logger = logging.getLogger(__name__)
|
|
29
29
|
def build_subparser(subparsers) -> None:
|
30
30
|
"""Build the subparser."""
|
31
31
|
gmi_parser = subparsers.add_parser(
|
32
|
-
"gmi", help="generate ebook in
|
32
|
+
"gmi", help="generate ebook in Gemtext format"
|
33
33
|
)
|
34
34
|
|
35
35
|
gmi_parser.set_defaults(func=run)
|
@@ -1,11 +1,11 @@
|
|
1
|
-
txt2ebook/__init__.py,sha256=
|
1
|
+
txt2ebook/__init__.py,sha256=wnrJownTB3sKXv3BpcXn4exkpWRSCXhKYWKJib5APNI,3073
|
2
2
|
txt2ebook/__main__.py,sha256=L29rlfPSx9XMnVaHBYP2dyYgDmutJvONR3yUejjYwRY,855
|
3
|
-
txt2ebook/cli.py,sha256=
|
3
|
+
txt2ebook/cli.py,sha256=Ed-58FCFYQQbBFJjA1f2aUTLhsxkoD4t67Y5WxWUNHQ,4288
|
4
4
|
txt2ebook/exceptions.py,sha256=PT3m85PE5QopHHUfRwEQzp0kJ4AA9yjLO6V6lYC8WhQ,858
|
5
5
|
txt2ebook/formats/__init__.py,sha256=yNF426_jHKNCKenKj1JTbOs22vEBuGScEk6TKhFaZUk,1716
|
6
6
|
txt2ebook/formats/base.py,sha256=ODguJ7OBPXfRQLLeoL-G66NZihroXb4kG5-56ZrlygI,5819
|
7
7
|
txt2ebook/formats/epub.py,sha256=IVz-FmYQlcChOw38YqfKy46bPVSIrHyxA_94iz06N3Y,6941
|
8
|
-
txt2ebook/formats/gmi.py,sha256=
|
8
|
+
txt2ebook/formats/gmi.py,sha256=kKyYzqS4NkucyhdBmT8cPEu6DGnNf95vVvXYdFnC6-s,6791
|
9
9
|
txt2ebook/formats/md.py,sha256=9RWv_7cfXfAGC1MdYm0WTkjpgtXKQJTQjYOf0MqQmsc,6537
|
10
10
|
txt2ebook/formats/pdf.py,sha256=xPsTAZ0UtDjKt2sTMKDnNLEMq6gSVNnxkK9XDlMhC9A,7281
|
11
11
|
txt2ebook/formats/templates/__init__.py,sha256=f3K7pJByNmmvu-wvziks6qb2QnnLmkDjUACXyw2s60E,760
|
@@ -32,11 +32,11 @@ txt2ebook/models/__init__.py,sha256=Z3zClWLj08Q8HgaWV1RRgIKatEhIUfYBAVWm-j4m05w,
|
|
32
32
|
txt2ebook/models/book.py,sha256=OkYg9ogOyH6mizP4qACTBTq4x6OAfY01gmaEzlerhLw,2788
|
33
33
|
txt2ebook/models/chapter.py,sha256=6YvUDHzR6amGMZgkQl_xHWrYZUmlfpF7mnDLilG2BpA,1686
|
34
34
|
txt2ebook/models/volume.py,sha256=koz1KfWjvGWLFbmGEQlZ23frsP93cDsuBMySYBHiXm8,1597
|
35
|
-
txt2ebook/parser.py,sha256=
|
35
|
+
txt2ebook/parser.py,sha256=fToC1LyOnPeQVjMasceVp2BSFwF9mfgyqa_3b3LAsY4,9005
|
36
36
|
txt2ebook/subcommands/__init__.py,sha256=ldhzvsrMsR8lZmhZef77JFz0jValpV3pytFfwJSkjls,1146
|
37
|
-
txt2ebook/subcommands/env.py,sha256=
|
37
|
+
txt2ebook/subcommands/env.py,sha256=NoebfEzrxjfrUTUvOHc14euyvrAD0W4SfUrBQQycJR8,1541
|
38
38
|
txt2ebook/subcommands/epub.py,sha256=JDDucrRiiQW1B7ycKz5zS1X5SMQZ82GBtlE2_SBYIdw,3507
|
39
|
-
txt2ebook/subcommands/gmi.py,sha256=
|
39
|
+
txt2ebook/subcommands/gmi.py,sha256=IE6NsQJz7Rz8mXmYgJJXuaaPP7gznf0ZNhxhWFxjjm0,3319
|
40
40
|
txt2ebook/subcommands/massage.py,sha256=EuC-C03NMJk9V1_PEUOa-n4SmQCRpj1TJ_GwSJE8_Ss,11809
|
41
41
|
txt2ebook/subcommands/md.py,sha256=P-oFtb2u-v2F_KU8t249-f5Ihjb_TCT_NWMlOYoq5p4,3330
|
42
42
|
txt2ebook/subcommands/parse.py,sha256=FaYTWa2yqkowwPAmHWJC7iCii2Rnus3SUHG10GjjJp4,3022
|
@@ -45,8 +45,8 @@ txt2ebook/subcommands/tex.py,sha256=X6ZBfuAs_mcJe8PNjzoW339ecPynZduVbcCq0henjiA,
|
|
45
45
|
txt2ebook/subcommands/typ.py,sha256=r4Xf7xSINbYfaIKkVzdyQDlUMWPvOIcbvOwC71spu6w,3682
|
46
46
|
txt2ebook/tokenizer.py,sha256=H9AaZVmNP43L3ONvj58u_5weZAjFG9SzQSeS9upGN1U,9642
|
47
47
|
txt2ebook/zh_utils.py,sha256=0Yq9r-JL4HntW68vFR6TBP9yQim1a07mfsh_sp-XmaE,4887
|
48
|
-
txt2ebook-0.1.
|
49
|
-
txt2ebook-0.1.
|
50
|
-
txt2ebook-0.1.
|
51
|
-
txt2ebook-0.1.
|
52
|
-
txt2ebook-0.1.
|
48
|
+
txt2ebook-0.1.132.dist-info/LICENSE.md,sha256=tGtFDwxWTjuR9syrJoSv1Hiffd2u8Tu8cYClfrXS_YU,31956
|
49
|
+
txt2ebook-0.1.132.dist-info/METADATA,sha256=zZgr9-_D7yRGvZXEUCw8_ldW1UCmTtbwCIzFXGQrje8,4969
|
50
|
+
txt2ebook-0.1.132.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
51
|
+
txt2ebook-0.1.132.dist-info/entry_points.txt,sha256=AFikuCV6fqf8_GHwsvWuo9jTGNrCkWY1TJWk5GfMWSk,71
|
52
|
+
txt2ebook-0.1.132.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|