txt2ebook 0.1.24__tar.gz → 0.1.26__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.
Files changed (37) hide show
  1. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/CHANGELOG.md +29 -0
  2. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/CONTRIBUTING.md +7 -1
  3. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/PKG-INFO +5 -5
  4. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/README.md +4 -3
  5. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/pyproject.toml +4 -2
  6. txt2ebook-0.1.26/setup.py +59 -0
  7. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/__init__.py +1 -1
  8. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/formats/__init__.py +5 -0
  9. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/formats/epub.py +7 -1
  10. txt2ebook-0.1.26/src/txt2ebook/formats/templates/epub/condense.css +42 -0
  11. txt2ebook-0.1.26/src/txt2ebook/formats/templates/epub/noindent.css +42 -0
  12. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/locales/en/LC_MESSAGES/txt2ebook.po +6 -6
  13. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/locales/txt2ebook.pot +6 -6
  14. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/locales/zh-cn/LC_MESSAGES/txt2ebook.po +6 -6
  15. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/parser.py +1 -2
  16. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/txt2ebook.py +4 -6
  17. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/zh_utils.py +13 -2
  18. txt2ebook-0.1.24/setup.py +0 -60
  19. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/LICENSE.md +0 -0
  20. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/__main__.py +0 -0
  21. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/exceptions.py +0 -0
  22. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/formats/templates/__init__.py +0 -0
  23. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/formats/templates/epub/__init__.py +0 -0
  24. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/formats/templates/epub/clean.css +0 -0
  25. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/formats/txt.py +0 -0
  26. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/helpers/__init__.py +0 -0
  27. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/languages/__init__.py +0 -0
  28. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/languages/en.py +0 -0
  29. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/languages/zh_cn.py +0 -0
  30. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/languages/zh_tw.py +0 -0
  31. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/locales/en/LC_MESSAGES/txt2ebook.mo +0 -0
  32. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/locales/zh-cn/LC_MESSAGES/txt2ebook.mo +0 -0
  33. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/models/__init__.py +0 -0
  34. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/models/book.py +0 -0
  35. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/models/chapter.py +0 -0
  36. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/models/volume.py +0 -0
  37. {txt2ebook-0.1.24 → txt2ebook-0.1.26}/src/txt2ebook/tokenizer.py +0 -0
@@ -7,6 +7,35 @@ and this project adheres to [0-based versioning](https://0ver.org/).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## v0.1.26 - 2023-03-12
11
+
12
+ ### Changed
13
+
14
+ - Rename epub template names, `clean_no_indent` to `noindent`, and
15
+ `clean_no_paragraph_space` to `condense`
16
+ - Raise warnings for invalid prepend length for `zh_words_to_numbers` function
17
+
18
+ ### Fixed
19
+
20
+ - Fix missing translations
21
+ - Fix missing EPUB template names not showing in help message
22
+
23
+ ## v0.1.25 - 2023-03-05
24
+
25
+ ### Added
26
+
27
+ - Add new EPUB templates, `clean_no_indent` and `clean_no_paragraph_space`
28
+
29
+ ### Fixed
30
+
31
+ - Add missing `zh-*` character for `zh_numeric`
32
+ - Remove unused import
33
+ - Fix incorrect dep added to wrong environment
34
+
35
+ ### Changed
36
+
37
+ - Refactor ebook extensions variable into package
38
+
10
39
  ## v0.1.24 - 2023-02-26
11
40
 
12
41
  ### Changed
@@ -53,11 +53,17 @@ tox -e py37,py38,py39,py310,py311 -- tests/test_tokenizer.py
53
53
  For code lint, we're using `pre-commit`:
54
54
 
55
55
  ```bash
56
- pre-commit install
56
+ pre-commit install # run once
57
57
  pre-commit clean
58
58
  pre-commit run --all-files
59
59
  ```
60
60
 
61
+ Or specific hook:
62
+
63
+ ```bash
64
+ pre-commit run pylint -a
65
+ ```
66
+
61
67
  We're using zero-based versioning.
62
68
 
63
69
  For patches or bug fixes:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: txt2ebook
3
- Version: 0.1.24
3
+ Version: 0.1.26
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
@@ -31,7 +31,6 @@ Requires-Dist: CJKwrap (>=2.2,<3.0)
31
31
  Requires-Dist: EbookLib (>=0.17.1,<0.18.0)
32
32
  Requires-Dist: bs4 (>=0.0.1,<0.0.2)
33
33
  Requires-Dist: langdetect (>=1.0.9,<2.0.0)
34
- Requires-Dist: pytest-xdist (>=3.1.0,<4.0.0)
35
34
  Requires-Dist: regex (>=2021.11.10,<2022.0.0)
36
35
  Requires-Dist: tox-pyenv (>=1.1.0,<2.0.0)
37
36
  Project-URL: Repository, https://github.com/kianmeng/txt2ebook
@@ -67,8 +66,9 @@ txt2ebook --help
67
66
  usage: txt2ebook [-f {epub,txt}] [-t TITLE] [-l LANGUAGE] [-a AUTHOR]
68
67
  [-c IMAGE_FILENAME] [-w WIDTH] [-ps SEPARATOR] [-rd REGEX]
69
68
  [-rvc REGEX] [-rv REGEX] [-rc REGEX] [-rt REGEX] [-ra REGEX]
70
- [-rl REGEX] [-rr REGEX REGEX] [-et TEMPLATE] [-vp] [-tp]
71
- [-sp] [-hn] [-fw] [-rw] [-ob] [-ow] [-v] [-d] [-h] [-V]
69
+ [-rl REGEX] [-rr REGEX REGEX] [-et {clean,noindent,condense}]
70
+ [-vp] [-tp] [-sp] [-hn] [-fw] [-rw] [-ob] [-ow] [-v] [-d]
71
+ [-h] [-V]
72
72
  TXT_FILENAME [EBOOK_FILENAME]
73
73
 
74
74
  txt2ebook/tte is a cli tool to convert txt file to ebook format.
@@ -112,7 +112,7 @@ optional arguments:
112
112
  regex to delete whole line (default: '[]')
113
113
  -rr REGEX REGEX, --regex-replace REGEX REGEX
114
114
  regex to search and replace (default: '[]')
115
- -et TEMPLATE, --epub-template TEMPLATE
115
+ -et {clean,noindent,condense}, --epub-template {clean,noindent,condense}
116
116
  CSS template for epub ebook (default: 'clean')
117
117
  -vp, --volume-page
118
118
  generate each volume as separate page (only 'epub' format)
@@ -28,8 +28,9 @@ txt2ebook --help
28
28
  usage: txt2ebook [-f {epub,txt}] [-t TITLE] [-l LANGUAGE] [-a AUTHOR]
29
29
  [-c IMAGE_FILENAME] [-w WIDTH] [-ps SEPARATOR] [-rd REGEX]
30
30
  [-rvc REGEX] [-rv REGEX] [-rc REGEX] [-rt REGEX] [-ra REGEX]
31
- [-rl REGEX] [-rr REGEX REGEX] [-et TEMPLATE] [-vp] [-tp]
32
- [-sp] [-hn] [-fw] [-rw] [-ob] [-ow] [-v] [-d] [-h] [-V]
31
+ [-rl REGEX] [-rr REGEX REGEX] [-et {clean,noindent,condense}]
32
+ [-vp] [-tp] [-sp] [-hn] [-fw] [-rw] [-ob] [-ow] [-v] [-d]
33
+ [-h] [-V]
33
34
  TXT_FILENAME [EBOOK_FILENAME]
34
35
 
35
36
  txt2ebook/tte is a cli tool to convert txt file to ebook format.
@@ -73,7 +74,7 @@ optional arguments:
73
74
  regex to delete whole line (default: '[]')
74
75
  -rr REGEX REGEX, --regex-replace REGEX REGEX
75
76
  regex to search and replace (default: '[]')
76
- -et TEMPLATE, --epub-template TEMPLATE
77
+ -et {clean,noindent,condense}, --epub-template {clean,noindent,condense}
77
78
  CSS template for epub ebook (default: 'clean')
78
79
  -vp, --volume-page
79
80
  generate each volume as separate page (only 'epub' format)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "txt2ebook"
3
- version = "0.1.24"
3
+ version = "0.1.26"
4
4
  description = "CLI tool to convert txt file to ebook format"
5
5
  authors = ["Kian-Meng Ang <kianmeng@cpan.org>"]
6
6
  license = "AGPL-3.0-or-later"
@@ -37,7 +37,6 @@ langdetect = "^1.0.9"
37
37
  python = "^3.7"
38
38
  regex = "^2021.11.10"
39
39
  tox-pyenv = "^1.1.0"
40
- pytest-xdist = "^3.1.0"
41
40
 
42
41
  [tool.poetry.dev-dependencies]
43
42
  bandit = "^1.7.1"
@@ -56,6 +55,9 @@ pre-commit = "^2.20.0"
56
55
  txt2ebook = 'txt2ebook.txt2ebook:main'
57
56
  tte = 'txt2ebook.txt2ebook:main'
58
57
 
58
+ [tool.poetry.group.dev.dependencies]
59
+ pytest-xdist = "^3.2.0"
60
+
59
61
  [build-system]
60
62
  build-backend = "poetry.core.masonry.api"
61
63
  requires = [
@@ -0,0 +1,59 @@
1
+ # -*- coding: utf-8 -*-
2
+ from setuptools import setup
3
+
4
+ package_dir = \
5
+ {'': 'src'}
6
+
7
+ packages = \
8
+ ['txt2ebook',
9
+ 'txt2ebook.formats',
10
+ 'txt2ebook.formats.templates',
11
+ 'txt2ebook.formats.templates.epub',
12
+ 'txt2ebook.helpers',
13
+ 'txt2ebook.languages',
14
+ 'txt2ebook.models']
15
+
16
+ package_data = \
17
+ {'': ['*'],
18
+ 'txt2ebook': ['locales/*',
19
+ 'locales/en/LC_MESSAGES/txt2ebook.mo',
20
+ 'locales/en/LC_MESSAGES/txt2ebook.mo',
21
+ 'locales/en/LC_MESSAGES/txt2ebook.po',
22
+ 'locales/en/LC_MESSAGES/txt2ebook.po',
23
+ 'locales/zh-cn/LC_MESSAGES/txt2ebook.mo',
24
+ 'locales/zh-cn/LC_MESSAGES/txt2ebook.mo',
25
+ 'locales/zh-cn/LC_MESSAGES/txt2ebook.po',
26
+ 'locales/zh-cn/LC_MESSAGES/txt2ebook.po']}
27
+
28
+ install_requires = \
29
+ ['CJKwrap>=2.2,<3.0',
30
+ 'EbookLib>=0.17.1,<0.18.0',
31
+ 'bs4>=0.0.1,<0.0.2',
32
+ 'langdetect>=1.0.9,<2.0.0',
33
+ 'regex>=2021.11.10,<2022.0.0',
34
+ 'tox-pyenv>=1.1.0,<2.0.0']
35
+
36
+ entry_points = \
37
+ {'console_scripts': ['tte = txt2ebook.txt2ebook:main',
38
+ 'txt2ebook = txt2ebook.txt2ebook:main']}
39
+
40
+ setup_kwargs = {
41
+ 'name': 'txt2ebook',
42
+ 'version': '0.1.26',
43
+ 'description': 'CLI tool to convert txt file to ebook format',
44
+ 'long_description': "# txt2ebook\n\nConsole tool to convert txt file to different ebook format.\n\n## Installation\n\nStable version From PyPI:\n\n```console\npython3 -m pip install txt2ebook\n```\n\nLatest development version from GitHub:\n\n```console\npython3 -m pip install -e git+https://github.com/kianmeng/txt2ebook.git\n```\n\n## Usage\n\nShowing help message of command-line options:\n\n```console\ntxt2ebook --help\n```\n\n```console\nusage: txt2ebook [-f {epub,txt}] [-t TITLE] [-l LANGUAGE] [-a AUTHOR]\n [-c IMAGE_FILENAME] [-w WIDTH] [-ps SEPARATOR] [-rd REGEX]\n [-rvc REGEX] [-rv REGEX] [-rc REGEX] [-rt REGEX] [-ra REGEX]\n [-rl REGEX] [-rr REGEX REGEX] [-et {clean,noindent,condense}]\n [-vp] [-tp] [-sp] [-hn] [-fw] [-rw] [-ob] [-ow] [-v] [-d]\n [-h] [-V]\n TXT_FILENAME [EBOOK_FILENAME]\n\ntxt2ebook/tte is a cli tool to convert txt file to ebook format.\n website: https://github.com/kianmeng/txt2ebook\n issues: https://github.com/kianmeng/txt2ebook/issues\n\npositional arguments:\n TXT_FILENAME\n source text filename\n EBOOK_FILENAME\n converted ebook filename (default: 'TXT_FILENAME.{epub,txt}')\n\noptional arguments:\n -f {epub,txt}, --format {epub,txt}\n ebook format (default: '['epub', 'txt']')\n -t TITLE, --title TITLE\n title of the ebook (default: 'None')\n -l LANGUAGE, --language LANGUAGE\n language of the ebook (default: 'None')\n -a AUTHOR, --author AUTHOR\n author of the ebook (default: '[]')\n -c IMAGE_FILENAME, --cover IMAGE_FILENAME\n cover of the ebook\n -w WIDTH, --width WIDTH\n width for line wrapping\n -ps SEPARATOR, --paragraph_separator SEPARATOR\n paragraph separator (default: '\\n\\n')\n -rd REGEX, --regex-delete REGEX\n regex to delete word or phrase (default: '[]')\n -rvc REGEX, --regex-volume-chapter REGEX\n regex to parse volume and chapter header (default: by LANGUAGE)\n -rv REGEX, --regex-volume REGEX\n regex to parse volume header (default: by LANGUAGE)\n -rc REGEX, --regex-chapter REGEX\n regex to parse chapter header (default: by LANGUAGE)\n -rt REGEX, --regex-title REGEX\n regex to parse title of the book (default: by LANGUAGE)\n -ra REGEX, --regex-author REGEX\n regex to parse author of the book (default: by LANGUAGE)\n -rl REGEX, --regex-delete-line REGEX\n regex to delete whole line (default: '[]')\n -rr REGEX REGEX, --regex-replace REGEX REGEX\n regex to search and replace (default: '[]')\n -et {clean,noindent,condense}, --epub-template {clean,noindent,condense}\n CSS template for epub ebook (default: 'clean')\n -vp, --volume-page\n generate each volume as separate page (only 'epub' format)\n -tp, --test-parsing\n test parsing for volume/chapter header\n -sp, --split-volume-and-chapter\n Split volume or chapter into separate file (only 'txt' format).\n Both --overwrite-backup and --overwrite option will be ignore.\n -hn, --header-number\n convert section header from words to numbers (only 'zh-cn/zh-tw' language)\n -fw, --fullwidth\n convert ASCII character from halfwidth to fullwidth (only 'zh-cn/zh-tw' language)\n -rw, --raise-on-warning\n raise exception and stop parsing upon warning\n -ob, --overwrite-backup\n overwrite massaged and backup original TXT_FILENAME\n -ow, --overwrite\n overwrite massaged TXT_FILENAME\n -v, --verbose\n show verbosity of debugging log, use -vv, -vvv for more details\n -d, --debug\n show debugging log and stacktrace\n -h, --help\n show this help message and exit\n -V, --version\n show program's version number and exit\n```\n\nConvert a txt file into epub:\n\n```console\ntxt2book ebook.txt\n```\n\n## Copyright and License\n\nCopyright (c) 2021,2022,2023 Kian-Meng Ang\n\nThis program is free software: you can redistribute it and/or modify it under\nthe terms of the GNU Affero General Public License as published by the Free\nSoftware Foundation, either version 3 of the License, or (at your option) any\nlater version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY\nWARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A\nPARTICULAR PURPOSE. See the GNU Affero General Public License for more details.\n\nYou should have received a copy of the GNU Affero General Public License along\nwith this program. If not, see <https://www.gnu.org/licenses/>.\n",
45
+ 'author': 'Kian-Meng Ang',
46
+ 'author_email': 'kianmeng@cpan.org',
47
+ 'maintainer': 'None',
48
+ 'maintainer_email': 'None',
49
+ 'url': 'https://github.com/kianmeng/txt2ebook',
50
+ 'package_dir': package_dir,
51
+ 'packages': packages,
52
+ 'package_data': package_data,
53
+ 'install_requires': install_requires,
54
+ 'entry_points': entry_points,
55
+ 'python_requires': '>=3.7,<4.0',
56
+ }
57
+
58
+
59
+ setup(**setup_kwargs)
@@ -21,7 +21,7 @@ import sys
21
21
 
22
22
  logger = logging.getLogger(__name__)
23
23
 
24
- __version__ = "0.1.24"
24
+ __version__ = "0.1.26"
25
25
 
26
26
 
27
27
  def setup_logger(config: argparse.Namespace) -> None:
@@ -19,11 +19,14 @@ import argparse
19
19
  from typing import Union
20
20
 
21
21
  import txt2ebook.models.book
22
+ from txt2ebook.formats.epub import TEMPLATES as EPUB_TEMPLATES
22
23
  from txt2ebook.formats.epub import EpubWriter
23
24
  from txt2ebook.formats.txt import TxtWriter
24
25
  from txt2ebook.helpers import load_class, to_classname
25
26
  from txt2ebook.models import Book
26
27
 
28
+ EBOOK_FORMATS = ["epub", "txt"]
29
+
27
30
 
28
31
  def create_format(
29
32
  book: txt2ebook.models.book.Book,
@@ -49,6 +52,8 @@ def create_format(
49
52
 
50
53
  __all__ = [
51
54
  "Book",
55
+ "EBOOK_FORMATS",
56
+ "EPUB_TEMPLATES",
52
57
  "EpubWriter",
53
58
  "TxtWriter",
54
59
  ]
@@ -19,7 +19,7 @@ import gettext
19
19
  import io
20
20
  import logging
21
21
  import uuid
22
- from importlib.resources import read_text
22
+ from importlib.resources import contents, read_text
23
23
  from pathlib import Path
24
24
  from typing import Optional, Union
25
25
 
@@ -32,6 +32,12 @@ logger = logging.getLogger(__name__)
32
32
 
33
33
  SPACE = "\u0020"
34
34
 
35
+ TEMPLATES = [
36
+ Path(file).stem
37
+ for file in list(contents(template_epub))
38
+ if Path(file).suffix == ".css"
39
+ ]
40
+
35
41
 
36
42
  class EpubWriter:
37
43
  """Module for writing ebook in epub format."""
@@ -0,0 +1,42 @@
1
+ /* cover page */
2
+ div#cover {
3
+ text-align: center;
4
+ width: 100%;
5
+ }
6
+
7
+ /* navigation page - toc */
8
+ ol {
9
+ list-style-type: none;
10
+ padding-left: 0;
11
+ }
12
+
13
+ ol li {
14
+ padding-top: 0.2em;
15
+ }
16
+
17
+ ol li ol li:last-of-type {
18
+ padding-bottom: 1em;
19
+ }
20
+
21
+ ol li a {
22
+ text-decoration: none;
23
+ }
24
+
25
+ /* chapters & section */
26
+ div.volume {
27
+ display: table;
28
+ width: 100%;
29
+ height: 100%;
30
+ }
31
+
32
+ h1.volume {
33
+ display: table-cell;
34
+ text-align: center;
35
+ vertical-align: middle;
36
+ }
37
+
38
+ h2 {
39
+ }
40
+ p {
41
+ margin: 0em;
42
+ }
@@ -0,0 +1,42 @@
1
+ /* cover page */
2
+ div#cover {
3
+ text-align: center;
4
+ width: 100%;
5
+ }
6
+
7
+ /* navigation page - toc */
8
+ ol {
9
+ list-style-type: none;
10
+ padding-left: 0;
11
+ }
12
+
13
+ ol li {
14
+ padding-top: 0.2em;
15
+ }
16
+
17
+ ol li ol li:last-of-type {
18
+ padding-bottom: 1em;
19
+ }
20
+
21
+ ol li a {
22
+ text-decoration: none;
23
+ }
24
+
25
+ /* chapters & section */
26
+ div.volume {
27
+ display: table;
28
+ width: 100%;
29
+ height: 100%;
30
+ }
31
+
32
+ h1.volume {
33
+ display: table-cell;
34
+ text-align: center;
35
+ vertical-align: middle;
36
+ }
37
+
38
+ h2 {
39
+ }
40
+ p {
41
+ text-indent: -2em;
42
+ }
@@ -5,7 +5,7 @@
5
5
  msgid ""
6
6
  msgstr ""
7
7
  "Project-Id-Version: PACKAGE VERSION\n"
8
- "POT-Creation-Date: 2023-02-04 22:03+0800\n"
8
+ "POT-Creation-Date: 2023-03-06 04:02+0800\n"
9
9
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
10
10
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
11
11
  "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -15,22 +15,22 @@ msgstr ""
15
15
  "Content-Transfer-Encoding: 8bit\n"
16
16
  "Generated-By: pygettext.py 1.5\n"
17
17
 
18
- #: src/txt2ebook/formats/epub.py:193
18
+ #: src/txt2ebook/formats/epub.py:199
19
19
  msgid "cover"
20
20
  msgstr "Cover"
21
21
 
22
- #: src/txt2ebook/formats/txt.py:88
22
+ #: src/txt2ebook/formats/txt.py:84
23
23
  msgid "metadata"
24
24
  msgstr "metadata"
25
25
 
26
- #: src/txt2ebook/formats/txt.py:158
26
+ #: src/txt2ebook/formats/txt.py:154
27
27
  msgid "title:"
28
28
  msgstr "Title:"
29
29
 
30
- #: src/txt2ebook/formats/txt.py:159
30
+ #: src/txt2ebook/formats/txt.py:155
31
31
  msgid "author:"
32
32
  msgstr "Author:"
33
33
 
34
- #: src/txt2ebook/formats/txt.py:160
34
+ #: src/txt2ebook/formats/txt.py:156
35
35
  msgid "tag:"
36
36
  msgstr "Tag:"
@@ -5,7 +5,7 @@
5
5
  msgid ""
6
6
  msgstr ""
7
7
  "Project-Id-Version: PACKAGE VERSION\n"
8
- "POT-Creation-Date: 2023-02-05 10:12+0800\n"
8
+ "POT-Creation-Date: 2023-03-06 04:02+0800\n"
9
9
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
10
10
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
11
11
  "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -15,23 +15,23 @@ msgstr ""
15
15
  "Generated-By: pygettext.py 1.5\n"
16
16
 
17
17
 
18
- #: src/txt2ebook/formats/epub.py:193
18
+ #: src/txt2ebook/formats/epub.py:199
19
19
  msgid "cover"
20
20
  msgstr ""
21
21
 
22
- #: src/txt2ebook/formats/txt.py:88
22
+ #: src/txt2ebook/formats/txt.py:84
23
23
  msgid "metadata"
24
24
  msgstr ""
25
25
 
26
- #: src/txt2ebook/formats/txt.py:158
26
+ #: src/txt2ebook/formats/txt.py:154
27
27
  msgid "title:"
28
28
  msgstr ""
29
29
 
30
- #: src/txt2ebook/formats/txt.py:159
30
+ #: src/txt2ebook/formats/txt.py:155
31
31
  msgid "author:"
32
32
  msgstr ""
33
33
 
34
- #: src/txt2ebook/formats/txt.py:160
34
+ #: src/txt2ebook/formats/txt.py:156
35
35
  msgid "tag:"
36
36
  msgstr ""
37
37
 
@@ -5,7 +5,7 @@
5
5
  msgid ""
6
6
  msgstr ""
7
7
  "Project-Id-Version: \n"
8
- "POT-Creation-Date: 2023-02-04 22:03+0800\n"
8
+ "POT-Creation-Date: 2023-03-06 04:02+0800\n"
9
9
  "PO-Revision-Date: 2023-01-14 18:07+0800\n"
10
10
  "Last-Translator: \n"
11
11
  "Language-Team: \n"
@@ -16,22 +16,22 @@ msgstr ""
16
16
  "Generated-By: pygettext.py 1.5\n"
17
17
  "X-Generator: Poedit 3.1.1\n"
18
18
 
19
- #: src/txt2ebook/formats/epub.py:193
19
+ #: src/txt2ebook/formats/epub.py:199
20
20
  msgid "cover"
21
21
  msgstr "封面"
22
22
 
23
- #: src/txt2ebook/formats/txt.py:88
23
+ #: src/txt2ebook/formats/txt.py:84
24
24
  msgid "metadata"
25
25
  msgstr "元数据"
26
26
 
27
- #: src/txt2ebook/formats/txt.py:158
27
+ #: src/txt2ebook/formats/txt.py:154
28
28
  msgid "title:"
29
29
  msgstr "书名:"
30
30
 
31
- #: src/txt2ebook/formats/txt.py:159
31
+ #: src/txt2ebook/formats/txt.py:155
32
32
  msgid "author:"
33
33
  msgstr "作者:"
34
34
 
35
- #: src/txt2ebook/formats/txt.py:160
35
+ #: src/txt2ebook/formats/txt.py:156
36
36
  msgid "tag:"
37
37
  msgstr "票签:"
@@ -26,7 +26,7 @@ import regex as re
26
26
 
27
27
  from txt2ebook.models import Book, Chapter, Volume
28
28
  from txt2ebook.tokenizer import Tokenizer
29
- from txt2ebook.zh_utils import zh_halfwidth_to_fullwidth, zh_numeric, zh_words_to_numbers
29
+ from txt2ebook.zh_utils import zh_halfwidth_to_fullwidth, zh_words_to_numbers
30
30
 
31
31
  logger = logging.getLogger(__name__)
32
32
 
@@ -135,7 +135,6 @@ class Parser:
135
135
  )
136
136
  return replaced_words
137
137
 
138
-
139
138
  def parse_tokens(self, tokenizer: Tokenizer) -> Tuple:
140
139
  """Parse the tokens and organize into book structure."""
141
140
  toc: List[Union[Volume, Chapter]] = []
@@ -26,11 +26,9 @@ from langdetect import detect
26
26
 
27
27
  from txt2ebook import __version__, setup_logger
28
28
  from txt2ebook.exceptions import EmptyFileError
29
- from txt2ebook.formats import create_format
29
+ from txt2ebook.formats import EBOOK_FORMATS, EPUB_TEMPLATES, create_format
30
30
  from txt2ebook.parser import Parser
31
31
 
32
- EBOOK_EXTS = ["epub", "txt"]
33
-
34
32
  logger = logging.getLogger(__name__)
35
33
 
36
34
 
@@ -104,7 +102,7 @@ def build_parser(
104
102
  default=None,
105
103
  help=(
106
104
  "converted ebook filename "
107
- "(default: 'TXT_FILENAME.{" + ",".join(EBOOK_EXTS) + "}')"
105
+ "(default: 'TXT_FILENAME.{" + ",".join(EBOOK_FORMATS) + "}')"
108
106
  ),
109
107
  metavar="EBOOK_FILENAME",
110
108
  )
@@ -114,7 +112,7 @@ def build_parser(
114
112
  "--format",
115
113
  dest="format",
116
114
  default=["epub", "txt"],
117
- choices=EBOOK_EXTS,
115
+ choices=EBOOK_FORMATS,
118
116
  action="append",
119
117
  help="ebook format (default: '%(default)s')",
120
118
  )
@@ -264,9 +262,9 @@ def build_parser(
264
262
  "-et",
265
263
  "--epub-template",
266
264
  default="clean",
265
+ choices=EPUB_TEMPLATES,
267
266
  dest="epub_template",
268
267
  help="CSS template for epub ebook (default: '%(default)s')",
269
- metavar="TEMPLATE",
270
268
  )
271
269
 
272
270
  parser.add_argument(
@@ -16,10 +16,12 @@
16
16
  """String helper functions for handling zh related text."""
17
17
 
18
18
  import re
19
+ import warnings
19
20
  from typing import Any
20
21
  from unicodedata import numeric
21
22
 
22
23
  WORD_NUMERIC_MAP = {
24
+ "两": 2.0,
23
25
  "圩": 50.0,
24
26
  "圓": 60.0,
25
27
  "進": 70.0,
@@ -130,9 +132,18 @@ def zh_words_to_numbers(words: str, length: int = 0) -> str:
130
132
  header_nums += int(zh_numeric(word_grp))
131
133
 
132
134
  padded_header_nums = str(header_nums)
133
- # todo: padded_header_nums length must smaller than length
135
+
134
136
  if length > 0:
135
- padded_header_nums = padded_header_nums.rjust(length, "0")
137
+ word_length = len(padded_header_nums)
138
+ if word_length < length:
139
+ padded_header_nums = padded_header_nums.rjust(length, "0")
140
+ else:
141
+ warnings.warn(
142
+ (
143
+ "prepend zero length less than word length, "
144
+ f"word length: {word_length}, prepend length: {length}"
145
+ )
146
+ )
136
147
 
137
148
  replaced_words = words.replace(header_words, padded_header_nums)
138
149
  return replaced_words
txt2ebook-0.1.24/setup.py DELETED
@@ -1,60 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- from setuptools import setup
3
-
4
- package_dir = \
5
- {'': 'src'}
6
-
7
- packages = \
8
- ['txt2ebook',
9
- 'txt2ebook.formats',
10
- 'txt2ebook.formats.templates',
11
- 'txt2ebook.formats.templates.epub',
12
- 'txt2ebook.helpers',
13
- 'txt2ebook.languages',
14
- 'txt2ebook.models']
15
-
16
- package_data = \
17
- {'': ['*'],
18
- 'txt2ebook': ['locales/*',
19
- 'locales/en/LC_MESSAGES/txt2ebook.mo',
20
- 'locales/en/LC_MESSAGES/txt2ebook.mo',
21
- 'locales/en/LC_MESSAGES/txt2ebook.po',
22
- 'locales/en/LC_MESSAGES/txt2ebook.po',
23
- 'locales/zh-cn/LC_MESSAGES/txt2ebook.mo',
24
- 'locales/zh-cn/LC_MESSAGES/txt2ebook.mo',
25
- 'locales/zh-cn/LC_MESSAGES/txt2ebook.po',
26
- 'locales/zh-cn/LC_MESSAGES/txt2ebook.po']}
27
-
28
- install_requires = \
29
- ['CJKwrap>=2.2,<3.0',
30
- 'EbookLib>=0.17.1,<0.18.0',
31
- 'bs4>=0.0.1,<0.0.2',
32
- 'langdetect>=1.0.9,<2.0.0',
33
- 'pytest-xdist>=3.1.0,<4.0.0',
34
- 'regex>=2021.11.10,<2022.0.0',
35
- 'tox-pyenv>=1.1.0,<2.0.0']
36
-
37
- entry_points = \
38
- {'console_scripts': ['tte = txt2ebook.txt2ebook:main',
39
- 'txt2ebook = txt2ebook.txt2ebook:main']}
40
-
41
- setup_kwargs = {
42
- 'name': 'txt2ebook',
43
- 'version': '0.1.24',
44
- 'description': 'CLI tool to convert txt file to ebook format',
45
- 'long_description': "# txt2ebook\n\nConsole tool to convert txt file to different ebook format.\n\n## Installation\n\nStable version From PyPI:\n\n```console\npython3 -m pip install txt2ebook\n```\n\nLatest development version from GitHub:\n\n```console\npython3 -m pip install -e git+https://github.com/kianmeng/txt2ebook.git\n```\n\n## Usage\n\nShowing help message of command-line options:\n\n```console\ntxt2ebook --help\n```\n\n```console\nusage: txt2ebook [-f {epub,txt}] [-t TITLE] [-l LANGUAGE] [-a AUTHOR]\n [-c IMAGE_FILENAME] [-w WIDTH] [-ps SEPARATOR] [-rd REGEX]\n [-rvc REGEX] [-rv REGEX] [-rc REGEX] [-rt REGEX] [-ra REGEX]\n [-rl REGEX] [-rr REGEX REGEX] [-et TEMPLATE] [-vp] [-tp]\n [-sp] [-hn] [-fw] [-rw] [-ob] [-ow] [-v] [-d] [-h] [-V]\n TXT_FILENAME [EBOOK_FILENAME]\n\ntxt2ebook/tte is a cli tool to convert txt file to ebook format.\n website: https://github.com/kianmeng/txt2ebook\n issues: https://github.com/kianmeng/txt2ebook/issues\n\npositional arguments:\n TXT_FILENAME\n source text filename\n EBOOK_FILENAME\n converted ebook filename (default: 'TXT_FILENAME.{epub,txt}')\n\noptional arguments:\n -f {epub,txt}, --format {epub,txt}\n ebook format (default: '['epub', 'txt']')\n -t TITLE, --title TITLE\n title of the ebook (default: 'None')\n -l LANGUAGE, --language LANGUAGE\n language of the ebook (default: 'None')\n -a AUTHOR, --author AUTHOR\n author of the ebook (default: '[]')\n -c IMAGE_FILENAME, --cover IMAGE_FILENAME\n cover of the ebook\n -w WIDTH, --width WIDTH\n width for line wrapping\n -ps SEPARATOR, --paragraph_separator SEPARATOR\n paragraph separator (default: '\\n\\n')\n -rd REGEX, --regex-delete REGEX\n regex to delete word or phrase (default: '[]')\n -rvc REGEX, --regex-volume-chapter REGEX\n regex to parse volume and chapter header (default: by LANGUAGE)\n -rv REGEX, --regex-volume REGEX\n regex to parse volume header (default: by LANGUAGE)\n -rc REGEX, --regex-chapter REGEX\n regex to parse chapter header (default: by LANGUAGE)\n -rt REGEX, --regex-title REGEX\n regex to parse title of the book (default: by LANGUAGE)\n -ra REGEX, --regex-author REGEX\n regex to parse author of the book (default: by LANGUAGE)\n -rl REGEX, --regex-delete-line REGEX\n regex to delete whole line (default: '[]')\n -rr REGEX REGEX, --regex-replace REGEX REGEX\n regex to search and replace (default: '[]')\n -et TEMPLATE, --epub-template TEMPLATE\n CSS template for epub ebook (default: 'clean')\n -vp, --volume-page\n generate each volume as separate page (only 'epub' format)\n -tp, --test-parsing\n test parsing for volume/chapter header\n -sp, --split-volume-and-chapter\n Split volume or chapter into separate file (only 'txt' format).\n Both --overwrite-backup and --overwrite option will be ignore.\n -hn, --header-number\n convert section header from words to numbers (only 'zh-cn/zh-tw' language)\n -fw, --fullwidth\n convert ASCII character from halfwidth to fullwidth (only 'zh-cn/zh-tw' language)\n -rw, --raise-on-warning\n raise exception and stop parsing upon warning\n -ob, --overwrite-backup\n overwrite massaged and backup original TXT_FILENAME\n -ow, --overwrite\n overwrite massaged TXT_FILENAME\n -v, --verbose\n show verbosity of debugging log, use -vv, -vvv for more details\n -d, --debug\n show debugging log and stacktrace\n -h, --help\n show this help message and exit\n -V, --version\n show program's version number and exit\n```\n\nConvert a txt file into epub:\n\n```console\ntxt2book ebook.txt\n```\n\n## Copyright and License\n\nCopyright (c) 2021,2022,2023 Kian-Meng Ang\n\nThis program is free software: you can redistribute it and/or modify it under\nthe terms of the GNU Affero General Public License as published by the Free\nSoftware Foundation, either version 3 of the License, or (at your option) any\nlater version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY\nWARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A\nPARTICULAR PURPOSE. See the GNU Affero General Public License for more details.\n\nYou should have received a copy of the GNU Affero General Public License along\nwith this program. If not, see <https://www.gnu.org/licenses/>.\n",
46
- 'author': 'Kian-Meng Ang',
47
- 'author_email': 'kianmeng@cpan.org',
48
- 'maintainer': 'None',
49
- 'maintainer_email': 'None',
50
- 'url': 'https://github.com/kianmeng/txt2ebook',
51
- 'package_dir': package_dir,
52
- 'packages': packages,
53
- 'package_data': package_data,
54
- 'install_requires': install_requires,
55
- 'entry_points': entry_points,
56
- 'python_requires': '>=3.7,<4.0',
57
- }
58
-
59
-
60
- setup(**setup_kwargs)
File without changes