txt2ebook 0.1.109__py3-none-any.whl → 0.1.113__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 CHANGED
@@ -22,7 +22,7 @@ import sys
22
22
 
23
23
  logger = logging.getLogger(__name__)
24
24
 
25
- __version__ = "0.1.109"
25
+ __version__ = "0.1.113"
26
26
 
27
27
 
28
28
  def setup_logger(config: argparse.Namespace) -> None:
txt2ebook/cli.py CHANGED
@@ -26,8 +26,12 @@ import sys
26
26
  from typing import Optional, Sequence
27
27
 
28
28
  import txt2ebook.subcommands.env
29
+ import txt2ebook.subcommands.epub
30
+ import txt2ebook.subcommands.gmi
29
31
  import txt2ebook.subcommands.massage
32
+ import txt2ebook.subcommands.md
30
33
  import txt2ebook.subcommands.parse
34
+ import txt2ebook.subcommands.pdf
31
35
  import txt2ebook.subcommands.tex
32
36
  from txt2ebook import __version__, setup_logger
33
37
 
@@ -283,7 +287,11 @@ def build_parser(
283
287
  subparsers = parser.add_subparsers(help="sub-command help")
284
288
  txt2ebook.subcommands.parse.build_subparser(subparsers)
285
289
  txt2ebook.subcommands.massage.build_subparser(subparsers)
290
+ txt2ebook.subcommands.epub.build_subparser(subparsers)
286
291
  txt2ebook.subcommands.tex.build_subparser(subparsers)
292
+ txt2ebook.subcommands.pdf.build_subparser(subparsers)
293
+ txt2ebook.subcommands.md.build_subparser(subparsers)
294
+ txt2ebook.subcommands.gmi.build_subparser(subparsers)
287
295
  txt2ebook.subcommands.env.build_subparser(subparsers)
288
296
 
289
297
  return parser
@@ -0,0 +1,94 @@
1
+ # Copyright (C) 2021,2022,2023,2024 Kian-Meng Ang
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU Affero General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU Affero General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Affero General Public License
14
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
15
+
16
+ """Epub subcommand."""
17
+
18
+ import argparse
19
+ import logging
20
+ import sys
21
+
22
+ from txt2ebook.subcommands.parse import run as parse_txt
23
+ from txt2ebook.formats.epub import EpubWriter
24
+ from txt2ebook.formats import EPUB_TEMPLATES
25
+
26
+
27
+ logger = logging.getLogger(__name__)
28
+
29
+
30
+ def build_subparser(subparsers) -> None:
31
+ """Build the subparser."""
32
+ epub_parser = subparsers.add_parser(
33
+ "epub", help="generate ebook in EPUB format"
34
+ )
35
+
36
+ epub_parser.set_defaults(func=run)
37
+
38
+ epub_parser.add_argument(
39
+ "input_file",
40
+ nargs=None if sys.stdin.isatty() else "?", # type: ignore
41
+ type=argparse.FileType("rb"),
42
+ default=None if sys.stdin.isatty() else sys.stdin,
43
+ help="source text filename",
44
+ metavar="TXT_FILENAME",
45
+ )
46
+
47
+ epub_parser.add_argument(
48
+ "output_file",
49
+ nargs="?",
50
+ default=None,
51
+ help="converted ebook filename (default: 'TXT_FILENAME.epub')",
52
+ metavar="EBOOK_FILENAME",
53
+ )
54
+
55
+ epub_parser.add_argument(
56
+ "-c",
57
+ "--cover",
58
+ dest="cover",
59
+ default=None,
60
+ help="cover of the ebook",
61
+ metavar="IMAGE_FILENAME",
62
+ )
63
+
64
+ epub_parser.add_argument(
65
+ "-et",
66
+ "--epub-template",
67
+ default="clean",
68
+ choices=EPUB_TEMPLATES,
69
+ dest="epub_template",
70
+ help="CSS template for epub ebook (default: '%(default)s')",
71
+ )
72
+
73
+ epub_parser.add_argument(
74
+ "-vp",
75
+ "--volume-page",
76
+ default=False,
77
+ action="store_true",
78
+ dest="volume_page",
79
+ help="generate each volume as separate page",
80
+ )
81
+
82
+
83
+ def run(args: argparse.Namespace) -> None:
84
+ """Run epub subcommand.
85
+
86
+ Args:
87
+ config (argparse.Namespace): Config from command line arguments
88
+
89
+ Returns:
90
+ None
91
+ """
92
+ book = parse_txt(args)
93
+ writer = EpubWriter(book, args)
94
+ writer.write()
@@ -0,0 +1,87 @@
1
+ # Copyright (C) 2021,2022,2023,2024 Kian-Meng Ang
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU Affero General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU Affero General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Affero General Public License
14
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
15
+
16
+ """gmi subcommand."""
17
+
18
+ import argparse
19
+ import logging
20
+ import sys
21
+
22
+ from txt2ebook.subcommands.parse import run as parse_txt
23
+ from txt2ebook.formats.gmi import GmiWriter
24
+
25
+
26
+ logger = logging.getLogger(__name__)
27
+
28
+
29
+ def build_subparser(subparsers) -> None:
30
+ """Build the subparser."""
31
+ gmi_parser = subparsers.add_parser(
32
+ "gmi", help="generate ebook in Markdown format"
33
+ )
34
+
35
+ gmi_parser.set_defaults(func=run)
36
+
37
+ gmi_parser.add_argument(
38
+ "input_file",
39
+ nargs=None if sys.stdin.isatty() else "?", # type: ignore
40
+ type=argparse.FileType("rb"),
41
+ default=None if sys.stdin.isatty() else sys.stdin,
42
+ help="source text filename",
43
+ metavar="TXT_FILENAME",
44
+ )
45
+
46
+ gmi_parser.add_argument(
47
+ "output_file",
48
+ nargs="?",
49
+ default=None,
50
+ help="converted ebook filename (default: 'TXT_FILENAME.md')",
51
+ metavar="EBOOK_FILENAME",
52
+ )
53
+
54
+ gmi_parser.add_argument(
55
+ "-sp",
56
+ "--split-volume-and-chapter",
57
+ default=False,
58
+ action="store_true",
59
+ dest="split_volume_and_chapter",
60
+ help=(
61
+ "split volume or chapter into separate file and "
62
+ "ignore the --overwrite option"
63
+ ),
64
+ )
65
+
66
+ gmi_parser.add_argument(
67
+ "-toc",
68
+ "--table-of-content",
69
+ default=False,
70
+ action="store_true",
71
+ dest="with_toc",
72
+ help="add table of content",
73
+ )
74
+
75
+
76
+ def run(args: argparse.Namespace) -> None:
77
+ """Run md subcommand.
78
+
79
+ Args:
80
+ config (argparse.Namespace): Config from command line arguments
81
+
82
+ Returns:
83
+ None
84
+ """
85
+ book = parse_txt(args)
86
+ writer = GmiWriter(book, args)
87
+ writer.write()
@@ -0,0 +1,87 @@
1
+ # Copyright (C) 2021,2022,2023,2024 Kian-Meng Ang
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU Affero General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU Affero General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Affero General Public License
14
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
15
+
16
+ """md subcommand."""
17
+
18
+ import argparse
19
+ import logging
20
+ import sys
21
+
22
+ from txt2ebook.subcommands.parse import run as parse_txt
23
+ from txt2ebook.formats.md import MdWriter as MarkdownWriter
24
+
25
+
26
+ logger = logging.getLogger(__name__)
27
+
28
+
29
+ def build_subparser(subparsers) -> None:
30
+ """Build the subparser."""
31
+ md_parser = subparsers.add_parser(
32
+ "md", help="generate ebook in Markdown format"
33
+ )
34
+
35
+ md_parser.set_defaults(func=run)
36
+
37
+ md_parser.add_argument(
38
+ "input_file",
39
+ nargs=None if sys.stdin.isatty() else "?", # type: ignore
40
+ type=argparse.FileType("rb"),
41
+ default=None if sys.stdin.isatty() else sys.stdin,
42
+ help="source text filename",
43
+ metavar="TXT_FILENAME",
44
+ )
45
+
46
+ md_parser.add_argument(
47
+ "output_file",
48
+ nargs="?",
49
+ default=None,
50
+ help="converted ebook filename (default: 'TXT_FILENAME.md')",
51
+ metavar="EBOOK_FILENAME",
52
+ )
53
+
54
+ md_parser.add_argument(
55
+ "-sp",
56
+ "--split-volume-and-chapter",
57
+ default=False,
58
+ action="store_true",
59
+ dest="split_volume_and_chapter",
60
+ help=(
61
+ "split volume or chapter into separate file and "
62
+ "ignore the --overwrite option"
63
+ ),
64
+ )
65
+
66
+ md_parser.add_argument(
67
+ "-toc",
68
+ "--table-of-content",
69
+ default=False,
70
+ action="store_true",
71
+ dest="with_toc",
72
+ help="add table of content",
73
+ )
74
+
75
+
76
+ def run(args: argparse.Namespace) -> None:
77
+ """Run md subcommand.
78
+
79
+ Args:
80
+ config (argparse.Namespace): Config from command line arguments
81
+
82
+ Returns:
83
+ None
84
+ """
85
+ book = parse_txt(args)
86
+ writer = MarkdownWriter(book, args)
87
+ writer.write()
@@ -19,6 +19,7 @@ import argparse
19
19
  import logging
20
20
  import sys
21
21
 
22
+ import jieba.analyse
22
23
  from bs4 import UnicodeDammit
23
24
  from langdetect import detect
24
25
 
@@ -80,6 +81,9 @@ def run(args: argparse.Namespace) -> Book:
80
81
  detect_language,
81
82
  )
82
83
 
84
+ tags = jieba.analyse.extract_tags(content, topK=100)
85
+ logger.info("tags: %s", " ".join(tags))
86
+
83
87
  parser = Parser(content, args)
84
88
  book = parser.parse()
85
89
 
@@ -0,0 +1,77 @@
1
+ # Copyright (C) 2021,2022,2023,2024 Kian-Meng Ang
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU Affero General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU Affero General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Affero General Public License
14
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
15
+
16
+ """pdf subcommand."""
17
+
18
+ import argparse
19
+ import logging
20
+ import sys
21
+
22
+ from txt2ebook.subcommands.parse import run as parse_txt
23
+ from txt2ebook.formats.pdf import PdfWriter
24
+ from txt2ebook.formats import PAGE_SIZES
25
+
26
+
27
+ logger = logging.getLogger(__name__)
28
+
29
+
30
+ def build_subparser(subparsers) -> None:
31
+ """Build the subparser."""
32
+ pdf_parser = subparsers.add_parser(
33
+ "pdf", help="generate ebook in Markdown format"
34
+ )
35
+
36
+ pdf_parser.set_defaults(func=run)
37
+
38
+ pdf_parser.add_argument(
39
+ "input_file",
40
+ nargs=None if sys.stdin.isatty() else "?", # type: ignore
41
+ type=argparse.FileType("rb"),
42
+ default=None if sys.stdin.isatty() else sys.stdin,
43
+ help="source text filename",
44
+ metavar="TXT_FILENAME",
45
+ )
46
+
47
+ pdf_parser.add_argument(
48
+ "output_file",
49
+ nargs="?",
50
+ default=None,
51
+ help="converted ebook filename (default: 'TXT_FILENAME.md')",
52
+ metavar="EBOOK_FILENAME",
53
+ )
54
+
55
+ pdf_parser.add_argument(
56
+ "-pz",
57
+ "--page-size",
58
+ dest="page_size",
59
+ default="a5",
60
+ choices=PAGE_SIZES,
61
+ help="page size of the ebook (default: '%(default)s')",
62
+ metavar="PAGE_SIZE",
63
+ )
64
+
65
+
66
+ def run(args: argparse.Namespace) -> None:
67
+ """Run md subcommand.
68
+
69
+ Args:
70
+ config (argparse.Namespace): Config from command line arguments
71
+
72
+ Returns:
73
+ None
74
+ """
75
+ book = parse_txt(args)
76
+ writer = PdfWriter(book, args)
77
+ writer.write()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: txt2ebook
3
- Version: 0.1.109
3
+ Version: 0.1.113
4
4
  Summary: CLI tool to convert txt file to ebook format
5
5
  Home-page: https://github.com/kianmeng/txt2ebook
6
6
  License: AGPL-3.0-or-later
@@ -29,6 +29,7 @@ Requires-Dist: CJKwrap (>=2.2,<3.0)
29
29
  Requires-Dist: EbookLib (>=0.17.1,<0.18.0)
30
30
  Requires-Dist: bs4 (>=0.0.1,<0.0.2)
31
31
  Requires-Dist: importlib-resources (>=6.1.1,<7.0.0)
32
+ Requires-Dist: jieba (>=0.42.1,<0.43.0)
32
33
  Requires-Dist: langdetect (>=1.0.9,<2.0.0)
33
34
  Requires-Dist: lxml (>=5.2.2,<6.0.0)
34
35
  Requires-Dist: pylatex (>=1.4.2,<2.0.0)
@@ -1,6 +1,6 @@
1
- txt2ebook/__init__.py,sha256=mfDMuY9O8IvXtzphAwq8wxUSbXR0VMUoCgiOcPFlN70,2062
1
+ txt2ebook/__init__.py,sha256=W5p9nvecvcQpGoxh8TFAZZ7r-2AU3L5cEfcBKlYcVik,2062
2
2
  txt2ebook/__main__.py,sha256=gMLvgpqc_BL4cBqNe0vqErRF5dlJPAbvqu1zndcAHYI,850
3
- txt2ebook/cli.py,sha256=ehog7m-ePN-KlkIizCNHIgEApn8VUvcW0UMSaKa3Gfo,8180
3
+ txt2ebook/cli.py,sha256=TDGcvM9eRILaxSb1TROjyUhNwrQqylRF8CgMyd5apDM,8544
4
4
  txt2ebook/exceptions.py,sha256=b2HDsXdqweLJbvSJEGt48nxvGkZq20SfYezSjwp77JU,842
5
5
  txt2ebook/formats/__init__.py,sha256=WhiRWGvbUjc8QZfhAIkKCg6GL8vNNlEF73meZSzYhDA,2463
6
6
  txt2ebook/formats/base.py,sha256=SMt6Op88-HoIxRA-tgPBNSlrt7-KZ-m5-BytAEJT4m0,5814
@@ -34,14 +34,18 @@ txt2ebook/models/chapter.py,sha256=buECAklNQgM3tDehzyVO9YfA_F0iXyLq2PaMZGV_Zaw,1
34
34
  txt2ebook/models/volume.py,sha256=HyT4XO9yZ8d0PgZVfMMyAYUDFv58RrUmsSFNNmU-sHY,1592
35
35
  txt2ebook/parser.py,sha256=2Dk1n51Czb3Tn_a1tgSSx5A-XNETVyuX4gJ9nQ-fPlQ,8707
36
36
  txt2ebook/subcommands/env.py,sha256=26wcAhEbjKfWYeNiIsjm9TTaBUyNDYx1MYUtV2ZFkmg,1481
37
+ txt2ebook/subcommands/epub.py,sha256=evZgvi1cHe3uCHgAwteJ2FlXFk3YOUekYNghVk7ySgE,2578
38
+ txt2ebook/subcommands/gmi.py,sha256=k-pDtP2OevgMACy6VeUSfiKLV0E4FyPA9t4wGLjJXu8,2405
37
39
  txt2ebook/subcommands/massage.py,sha256=on4Oqpv3WwOf6tZVGFzwq972oGa6TaJx7Is_0YSnmBI,5766
38
- txt2ebook/subcommands/parse.py,sha256=1QEVRzgDZYiwOs-36WYPNFIIc-GgKCp8eBxZKuzqQa8,2607
40
+ txt2ebook/subcommands/md.py,sha256=v-xSWEpe6p9hIDRh-Nk1uH43P9gOvy80g-qt11dG-aw,2418
41
+ txt2ebook/subcommands/parse.py,sha256=BpEHs-gFYbJK1-50FPUX_3INfuxkgL5Glgpd3IBdJfs,2730
42
+ txt2ebook/subcommands/pdf.py,sha256=cnmjavFg6aXSYWzXpQEH4QfiwkppzsbAsLdO3DNvcRo,2179
39
43
  txt2ebook/subcommands/tex.py,sha256=O2Sl-v8tTU_bMFDDukFYEyXBTecGzp3Ll8Gqom63Clk,2330
40
44
  txt2ebook/tokenizer.py,sha256=HJEub1NYTaH3FMfzzdaNpmimzgzGN942m9O7oDHqkuQ,9456
41
45
  txt2ebook/txt2ebook.py,sha256=GwWjSk2HbnGrOM59qFsPv2CMqAgv1GBxy_r1zkgBEvQ,13969
42
46
  txt2ebook/zh_utils.py,sha256=EgKVbwqYGaTGswQUGcOCeSfRelzwkAb9WWY9TrsX1x4,4882
43
- txt2ebook-0.1.109.dist-info/LICENSE.md,sha256=tGtFDwxWTjuR9syrJoSv1Hiffd2u8Tu8cYClfrXS_YU,31956
44
- txt2ebook-0.1.109.dist-info/METADATA,sha256=EmsL_p4QP_vWEJGC-e4rQ5kxBflizBoQ_hYowfN64Is,7754
45
- txt2ebook-0.1.109.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
46
- txt2ebook-0.1.109.dist-info/entry_points.txt,sha256=JLW3Iv7eUyABlQeUFiUWQhLKfRdnB9o5SIcNlneGR0Q,77
47
- txt2ebook-0.1.109.dist-info/RECORD,,
47
+ txt2ebook-0.1.113.dist-info/LICENSE.md,sha256=tGtFDwxWTjuR9syrJoSv1Hiffd2u8Tu8cYClfrXS_YU,31956
48
+ txt2ebook-0.1.113.dist-info/METADATA,sha256=JXGV45Ca0KsNn1xetSihcF69tuMD0JXQmwIJL2gjDKY,7794
49
+ txt2ebook-0.1.113.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
50
+ txt2ebook-0.1.113.dist-info/entry_points.txt,sha256=JLW3Iv7eUyABlQeUFiUWQhLKfRdnB9o5SIcNlneGR0Q,77
51
+ txt2ebook-0.1.113.dist-info/RECORD,,