txt2ebook 0.1.45__tar.gz → 0.1.52__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 (48) hide show
  1. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/PKG-INFO +16 -8
  2. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/README.md +15 -7
  3. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/pyproject.toml +5 -16
  4. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/__init__.py +15 -12
  5. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/formats/base.py +10 -23
  6. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/formats/epub.py +6 -4
  7. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/formats/gmi.py +11 -11
  8. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/formats/md.py +11 -11
  9. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/formats/pdf.py +6 -5
  10. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/formats/txt.py +15 -15
  11. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/languages/zh_tw.py +3 -0
  12. txt2ebook-0.1.52/src/txt2ebook/locales/en/LC_MESSAGES/txt2ebook.mo +0 -0
  13. txt2ebook-0.1.52/src/txt2ebook/locales/en/LC_MESSAGES/txt2ebook.po +31 -0
  14. txt2ebook-0.1.52/src/txt2ebook/locales/txt2ebook.pot +31 -0
  15. txt2ebook-0.1.52/src/txt2ebook/locales/zh-cn/LC_MESSAGES/txt2ebook.mo +0 -0
  16. txt2ebook-0.1.52/src/txt2ebook/locales/zh-cn/LC_MESSAGES/txt2ebook.po +31 -0
  17. txt2ebook-0.1.52/src/txt2ebook/locales/zh-tw/LC_MESSAGES/txt2ebook.mo +0 -0
  18. txt2ebook-0.1.52/src/txt2ebook/locales/zh-tw/LC_MESSAGES/txt2ebook.po +31 -0
  19. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/parser.py +42 -51
  20. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/txt2ebook.py +22 -2
  21. txt2ebook-0.1.45/CHANGELOG.md +0 -732
  22. txt2ebook-0.1.45/CONTRIBUTING.md +0 -124
  23. txt2ebook-0.1.45/src/txt2ebook/locales/en/LC_MESSAGES/txt2ebook.mo +0 -0
  24. txt2ebook-0.1.45/src/txt2ebook/locales/en/LC_MESSAGES/txt2ebook.po +0 -48
  25. txt2ebook-0.1.45/src/txt2ebook/locales/txt2ebook.pot +0 -48
  26. txt2ebook-0.1.45/src/txt2ebook/locales/zh-cn/LC_MESSAGES/txt2ebook.mo +0 -0
  27. txt2ebook-0.1.45/src/txt2ebook/locales/zh-cn/LC_MESSAGES/txt2ebook.po +0 -48
  28. txt2ebook-0.1.45/src/txt2ebook/locales/zh-tw/LC_MESSAGES/txt2ebook.mo +0 -0
  29. txt2ebook-0.1.45/src/txt2ebook/locales/zh-tw/LC_MESSAGES/txt2ebook.po +0 -43
  30. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/LICENSE.md +0 -0
  31. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/__main__.py +0 -0
  32. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/exceptions.py +0 -0
  33. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/formats/__init__.py +0 -0
  34. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/formats/templates/__init__.py +0 -0
  35. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/formats/templates/epub/__init__.py +0 -0
  36. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/formats/templates/epub/clean.css +0 -0
  37. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/formats/templates/epub/condense.css +0 -0
  38. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/formats/templates/epub/noindent.css +0 -0
  39. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/helpers/__init__.py +0 -0
  40. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/languages/__init__.py +0 -0
  41. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/languages/en.py +0 -0
  42. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/languages/zh_cn.py +3 -3
  43. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/models/__init__.py +0 -0
  44. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/models/book.py +0 -0
  45. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/models/chapter.py +0 -0
  46. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/models/volume.py +0 -0
  47. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/tokenizer.py +0 -0
  48. {txt2ebook-0.1.45 → txt2ebook-0.1.52}/src/txt2ebook/zh_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: txt2ebook
3
- Version: 0.1.45
3
+ Version: 0.1.52
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
@@ -63,17 +63,19 @@ txt2ebook --help
63
63
  ```
64
64
 
65
65
  ```console
66
- usage: txt2ebook [-f {epub,gmi,md,pdf,txt}] [-t TITLE] [-l LANGUAGE]
67
- [-a AUTHOR] [-tr TRANSLATOR] [-c IMAGE_FILENAME] [-w WIDTH]
68
- [-ff FILENAME_FORMAT] [-ps SEPARATOR] [-pz PAGE_SIZE]
69
- [-rd REGEX] [-rvc REGEX] [-rv REGEX] [-rc REGEX] [-rt REGEX]
70
- [-ra REGEX] [-rl REGEX] [-rr REGEX REGEX]
71
- [-et {clean,condense,noindent}] [-vp] [-tp] [-sp] [-toc]
72
- [-hn] [-fw] [-rw] [-ow] [-v] [-d] [-h] [-V]
66
+ usage: txt2ebook [-of OUTPUT_FOLDER] [-f {epub,gmi,md,pdf,txt}] [-t TITLE]
67
+ [-l LANGUAGE] [-a AUTHOR] [-tr TRANSLATOR]
68
+ [-c IMAGE_FILENAME] [-w WIDTH] [-ff FILENAME_FORMAT]
69
+ [-ps SEPARATOR] [-pz PAGE_SIZE] [-rd REGEX] [-rvc REGEX]
70
+ [-rv REGEX] [-rc REGEX] [-rt REGEX] [-ra REGEX] [-rl REGEX]
71
+ [-rr REGEX REGEX] [-et {clean,condense,noindent}] [-vp] [-tp]
72
+ [-sp] [-ss] [-toc] [-hn] [-fw] [-rw] [-ow] [-q] [-v] [-d]
73
+ [-h] [-V]
73
74
  TXT_FILENAME [EBOOK_FILENAME]
74
75
 
75
76
  txt2ebook/tte is a cli tool to convert txt file to ebook format.
76
77
  website: https://github.com/kianmeng/txt2ebook
78
+ changelog: https://github.com/kianmeng/txt2ebook/blob/master/CHANGELOG.md
77
79
  issues: https://github.com/kianmeng/txt2ebook/issues
78
80
 
79
81
  positional arguments:
@@ -83,6 +85,8 @@ positional arguments:
83
85
  converted ebook filename (default: 'TXT_FILENAME.epub')
84
86
 
85
87
  optional arguments:
88
+ -of OUTPUT_FOLDER, --output-folder OUTPUT_FOLDER
89
+ set default output folder (default: 'output')
86
90
  -f {epub,gmi,md,pdf,txt}, --format {epub,gmi,md,pdf,txt}
87
91
  ebook format (default: 'epub')
88
92
  -t TITLE, --title TITLE
@@ -119,10 +123,14 @@ optional arguments:
119
123
  regex to search and replace (default: '[]')
120
124
  -tp, --test-parsing
121
125
  test parsing for volume/chapter header
126
+ -ss, --sort-volume-and-chapter
127
+ short volume and chapter
122
128
  -rw, --raise-on-warning
123
129
  raise exception and stop parsing upon warning
124
130
  -ow, --overwrite
125
131
  overwrite massaged TXT_FILENAME
132
+ -q, --quiet
133
+ suppress all logging
126
134
  -v, --verbose
127
135
  show verbosity of debugging log, use -vv, -vvv for more details
128
136
  -d, --debug
@@ -25,17 +25,19 @@ txt2ebook --help
25
25
  ```
26
26
 
27
27
  ```console
28
- usage: txt2ebook [-f {epub,gmi,md,pdf,txt}] [-t TITLE] [-l LANGUAGE]
29
- [-a AUTHOR] [-tr TRANSLATOR] [-c IMAGE_FILENAME] [-w WIDTH]
30
- [-ff FILENAME_FORMAT] [-ps SEPARATOR] [-pz PAGE_SIZE]
31
- [-rd REGEX] [-rvc REGEX] [-rv REGEX] [-rc REGEX] [-rt REGEX]
32
- [-ra REGEX] [-rl REGEX] [-rr REGEX REGEX]
33
- [-et {clean,condense,noindent}] [-vp] [-tp] [-sp] [-toc]
34
- [-hn] [-fw] [-rw] [-ow] [-v] [-d] [-h] [-V]
28
+ usage: txt2ebook [-of OUTPUT_FOLDER] [-f {epub,gmi,md,pdf,txt}] [-t TITLE]
29
+ [-l LANGUAGE] [-a AUTHOR] [-tr TRANSLATOR]
30
+ [-c IMAGE_FILENAME] [-w WIDTH] [-ff FILENAME_FORMAT]
31
+ [-ps SEPARATOR] [-pz PAGE_SIZE] [-rd REGEX] [-rvc REGEX]
32
+ [-rv REGEX] [-rc REGEX] [-rt REGEX] [-ra REGEX] [-rl REGEX]
33
+ [-rr REGEX REGEX] [-et {clean,condense,noindent}] [-vp] [-tp]
34
+ [-sp] [-ss] [-toc] [-hn] [-fw] [-rw] [-ow] [-q] [-v] [-d]
35
+ [-h] [-V]
35
36
  TXT_FILENAME [EBOOK_FILENAME]
36
37
 
37
38
  txt2ebook/tte is a cli tool to convert txt file to ebook format.
38
39
  website: https://github.com/kianmeng/txt2ebook
40
+ changelog: https://github.com/kianmeng/txt2ebook/blob/master/CHANGELOG.md
39
41
  issues: https://github.com/kianmeng/txt2ebook/issues
40
42
 
41
43
  positional arguments:
@@ -45,6 +47,8 @@ positional arguments:
45
47
  converted ebook filename (default: 'TXT_FILENAME.epub')
46
48
 
47
49
  optional arguments:
50
+ -of OUTPUT_FOLDER, --output-folder OUTPUT_FOLDER
51
+ set default output folder (default: 'output')
48
52
  -f {epub,gmi,md,pdf,txt}, --format {epub,gmi,md,pdf,txt}
49
53
  ebook format (default: 'epub')
50
54
  -t TITLE, --title TITLE
@@ -81,10 +85,14 @@ optional arguments:
81
85
  regex to search and replace (default: '[]')
82
86
  -tp, --test-parsing
83
87
  test parsing for volume/chapter header
88
+ -ss, --sort-volume-and-chapter
89
+ short volume and chapter
84
90
  -rw, --raise-on-warning
85
91
  raise exception and stop parsing upon warning
86
92
  -ow, --overwrite
87
93
  overwrite massaged TXT_FILENAME
94
+ -q, --quiet
95
+ suppress all logging
88
96
  -v, --verbose
89
97
  show verbosity of debugging log, use -vv, -vvv for more details
90
98
  -d, --debug
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "txt2ebook"
3
- version = "0.1.45"
3
+ version = "0.1.52"
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"
@@ -26,11 +26,6 @@ classifiers = [
26
26
  "Topic :: Text Processing :: Markup :: HTML",
27
27
  "Topic :: Text Processing :: Markup :: Markdown",
28
28
  ]
29
- include = [
30
- "CHANGELOG.md",
31
- "CONTRIBUTING.md",
32
- "LICENSE.md",
33
- ]
34
29
 
35
30
  [tool.poetry.dependencies]
36
31
  CJKwrap = "^2.2"
@@ -50,7 +45,6 @@ pep8-naming = "^0.12.1"
50
45
  pre-commit = "^2.20.0"
51
46
  pylint = "^2.11.1"
52
47
  pytest = "^7.0"
53
- pytest-console-scripts = "^1.3.1"
54
48
  pytest-cov = "^3.0.0"
55
49
  pytest-randomly = "^3.12.0"
56
50
  pytest-xdist = "^3.2.1"
@@ -63,17 +57,12 @@ vulture = "^2.3"
63
57
  txt2ebook = 'txt2ebook.txt2ebook:main'
64
58
  tte = 'txt2ebook.txt2ebook:main'
65
59
 
60
+ [tool.poetry.group.dev.dependencies]
61
+ babel = "^2.12.1"
62
+ scripttest = "^1.3"
63
+
66
64
  [build-system]
67
65
  build-backend = "poetry.core.masonry.api"
68
66
  requires = [
69
67
  "poetry-core>=1",
70
68
  ]
71
-
72
- [tool.pytest.ini_options]
73
- script_launch_mode = "subprocess"
74
-
75
- [tool.isort]
76
- profile = "black"
77
-
78
- [tool.mypy]
79
- ignore_missing_imports = 1
@@ -21,7 +21,7 @@ import sys
21
21
 
22
22
  logger = logging.getLogger(__name__)
23
23
 
24
- __version__ = "0.1.45"
24
+ __version__ = "0.1.52"
25
25
 
26
26
 
27
27
  def setup_logger(config: argparse.Namespace) -> None:
@@ -30,17 +30,20 @@ def setup_logger(config: argparse.Namespace) -> None:
30
30
  Args:
31
31
  config(argparse.Namespace): Config that contains arguments
32
32
  """
33
- logformat = {
34
- True: "%(levelname)5s: %(message)s",
35
- False: "%(message)s",
36
- }
37
-
38
- logging.basicConfig(
39
- level=config.debug and logging.DEBUG or logging.INFO,
40
- stream=sys.stdout,
41
- format=logformat[config.debug],
42
- datefmt="%Y-%m-%d %H:%M:%S",
43
- )
33
+ if config.quiet:
34
+ logging.disable(logging.NOTSET)
35
+ else:
36
+ logformat = {
37
+ True: "%(levelname)5s: %(message)s",
38
+ False: "%(message)s",
39
+ }
40
+
41
+ logging.basicConfig(
42
+ level=config.debug and logging.DEBUG or logging.INFO,
43
+ stream=sys.stdout,
44
+ format=logformat[config.debug],
45
+ datefmt="%Y-%m-%d %H:%M:%S",
46
+ )
44
47
 
45
48
 
46
49
  def log_or_raise_on_warning(msg: str, raise_on_warning: bool = False) -> None:
@@ -22,7 +22,6 @@ import logging
22
22
  from abc import ABC, abstractmethod
23
23
  from importlib import import_module
24
24
  from pathlib import Path
25
- from typing import Any
26
25
 
27
26
  from txt2ebook.helpers import lower_underscore
28
27
  from txt2ebook.models import Book, Chapter, Volume
@@ -53,21 +52,6 @@ class BaseWriter(ABC):
53
52
  self._load_translation()
54
53
  self.__post_init__()
55
54
 
56
- def __getattr__(self, key: str) -> Any:
57
- """Get a value of the config based on key name.
58
-
59
- Args:
60
- key(str): The key name of the config.
61
-
62
- Returns:
63
- Any: The value of a key, if found. Otherwise raise AttributeError
64
- exception.
65
- """
66
- if hasattr(self.config, key):
67
- return getattr(self.config, key)
68
-
69
- raise AttributeError(f"invalid config key: '{key}'!")
70
-
71
55
  def _load_translation(self):
72
56
  localedir = Path(Path(__file__).parent.parent, "locales")
73
57
  translation = gettext.translation(
@@ -79,13 +63,13 @@ class BaseWriter(ABC):
79
63
  if self.config.filename_format:
80
64
  filename = self.book.filename_format(self.config.filename_format)
81
65
  else:
82
- if self.output_file:
83
- filename = str(self.output_file)
66
+ if self.config.output_file:
67
+ filename = str(self.config.output_file)
84
68
  elif isinstance(
85
- self.input_file, (io.TextIOWrapper, io.BufferedReader)
69
+ self.config.input_file, (io.TextIOWrapper, io.BufferedReader)
86
70
  ):
87
- if self.input_file.name != "<stdin>":
88
- filename = self.input_file.name
71
+ if self.config.input_file.name != "<stdin>":
72
+ filename = self.config.input_file.name
89
73
  # input from redirection or piping
90
74
  elif self.book.title:
91
75
  filename = self.book.title
@@ -113,7 +97,10 @@ class BaseWriter(ABC):
113
97
  self._("tag:") + ",".join(self.book.tags),
114
98
  ]
115
99
  return (
116
- "---\n" + "\n".join(metadata) + "\n---" + self.paragraph_separator
100
+ "---\n"
101
+ + "\n".join(metadata)
102
+ + "\n---"
103
+ + self.config.paragraph_separator
117
104
  )
118
105
 
119
106
  def _to_toc(self, list_symbol, header_symbol="") -> str:
@@ -128,7 +115,7 @@ class BaseWriter(ABC):
128
115
  if isinstance(section, Chapter):
129
116
  toc += f"\n{list_symbol} " + section.title
130
117
 
131
- return toc + self.paragraph_separator
118
+ return toc + self.config.paragraph_separator
132
119
 
133
120
  @abstractmethod
134
121
  def write(self) -> None:
@@ -77,7 +77,7 @@ class EpubWriter(BaseWriter):
77
77
  book.spine.append(html_chapter)
78
78
  html_chapters.append(html_chapter)
79
79
 
80
- if self.volume_page:
80
+ if self.config.volume_page:
81
81
  logger.debug("Create separate volume page: %s", section)
82
82
  book.toc.append((html_volume, html_chapters))
83
83
  else:
@@ -100,8 +100,8 @@ class EpubWriter(BaseWriter):
100
100
  book.add_item(epub.EpubNcx())
101
101
 
102
102
  try:
103
- logger.info("Using EPUB template: %s", self.epub_template)
104
- css = read_text(template_epub, f"{self.epub_template}.css")
103
+ logger.info("Using EPUB template: %s", self.config.epub_template)
104
+ css = read_text(template_epub, f"{self.config.epub_template}.css")
105
105
 
106
106
  book_css = epub.EpubItem(
107
107
  uid="style_nav",
@@ -119,7 +119,9 @@ class EpubWriter(BaseWriter):
119
119
  book.spine.append("nav")
120
120
 
121
121
  except FileNotFoundError as error:
122
- logger.error("Unknown EPUB template name: %s", self.epub_template)
122
+ logger.error(
123
+ "Unknown EPUB template name: %s", self.config.epub_template
124
+ )
123
125
  raise SystemExit() from error
124
126
 
125
127
  def _gen_id(self) -> str:
@@ -31,7 +31,7 @@ class GmiWriter(BaseWriter):
31
31
 
32
32
  def write(self) -> None:
33
33
  """Generate GemText files."""
34
- if self.split_volume_and_chapter:
34
+ if self.config.split_volume_and_chapter:
35
35
  self._export_multiple_files()
36
36
  else:
37
37
  self._new_file()
@@ -39,7 +39,7 @@ class GmiWriter(BaseWriter):
39
39
  def _export_multiple_files(self) -> None:
40
40
  logger.info("Split multiple files")
41
41
 
42
- txt_filename = Path(self.input_file.name)
42
+ txt_filename = Path(self.config.input_file.name)
43
43
  export_filename = Path(
44
44
  txt_filename.resolve().parent.joinpath(
45
45
  lower_underscore(
@@ -52,7 +52,7 @@ class GmiWriter(BaseWriter):
52
52
  file.write(self._to_metadata_txt())
53
53
 
54
54
  sc_seq = 1
55
- if self.with_toc:
55
+ if self.config.with_toc:
56
56
  export_filename = Path(
57
57
  txt_filename.resolve().parent.joinpath(
58
58
  lower_underscore(
@@ -121,7 +121,7 @@ class GmiWriter(BaseWriter):
121
121
  file.write(self._to_md())
122
122
 
123
123
  def _to_md(self) -> str:
124
- toc = self._to_toc("*", "# ") if self.with_toc else ""
124
+ toc = self._to_toc("*", "# ") if self.config.with_toc else ""
125
125
  return self._to_metadata_txt() + toc + self._to_body_txt()
126
126
 
127
127
  def _to_body_txt(self) -> str:
@@ -132,13 +132,13 @@ class GmiWriter(BaseWriter):
132
132
  if isinstance(section, Chapter):
133
133
  content.append(self._to_chapter_txt(section))
134
134
 
135
- return f"{self.paragraph_separator}".join(content)
135
+ return f"{self.config.paragraph_separator}".join(content)
136
136
 
137
137
  def _to_volume_txt(self, volume) -> str:
138
138
  return (
139
139
  f"# {volume.title}"
140
- + self.paragraph_separator
141
- + self.paragraph_separator.join(
140
+ + self.config.paragraph_separator
141
+ + self.config.paragraph_separator.join(
142
142
  [
143
143
  self._to_chapter_txt(chapter, True)
144
144
  for chapter in volume.chapters
@@ -150,8 +150,8 @@ class GmiWriter(BaseWriter):
150
150
  header = "##" if part_of_volume else "#"
151
151
  return (
152
152
  f"{header} {chapter.title}"
153
- + self.paragraph_separator
154
- + self.paragraph_separator.join(
153
+ + self.config.paragraph_separator
154
+ + self.config.paragraph_separator.join(
155
155
  self._remove_newline(chapter.paragraphs)
156
156
  )
157
157
  )
@@ -159,8 +159,8 @@ class GmiWriter(BaseWriter):
159
159
  def _to_volume_chapter_txt(self, volume, chapter) -> str:
160
160
  return (
161
161
  f"# {volume.title} {chapter.title}"
162
- + self.paragraph_separator
163
- + self.paragraph_separator.join(
162
+ + self.config.paragraph_separator
163
+ + self.config.paragraph_separator.join(
164
164
  self._remove_newline(chapter.paragraphs)
165
165
  )
166
166
  )
@@ -30,7 +30,7 @@ class MdWriter(BaseWriter):
30
30
 
31
31
  def write(self) -> None:
32
32
  """Generate Markdown files."""
33
- if self.split_volume_and_chapter:
33
+ if self.config.split_volume_and_chapter:
34
34
  self._export_multiple_files()
35
35
  else:
36
36
  self._new_file()
@@ -38,7 +38,7 @@ class MdWriter(BaseWriter):
38
38
  def _export_multiple_files(self) -> None:
39
39
  logger.info("Split multiple files")
40
40
 
41
- txt_filename = Path(self.input_file.name)
41
+ txt_filename = Path(self.config.input_file.name)
42
42
  export_filename = Path(
43
43
  txt_filename.resolve().parent.joinpath(
44
44
  lower_underscore(
@@ -51,7 +51,7 @@ class MdWriter(BaseWriter):
51
51
  file.write(self._to_metadata_txt())
52
52
 
53
53
  sc_seq = 1
54
- if self.with_toc:
54
+ if self.config.with_toc:
55
55
  export_filename = Path(
56
56
  txt_filename.resolve().parent.joinpath(
57
57
  lower_underscore(
@@ -120,7 +120,7 @@ class MdWriter(BaseWriter):
120
120
  file.write(self._to_md())
121
121
 
122
122
  def _to_md(self) -> str:
123
- toc = self._to_toc("-", "# ") if self.with_toc else ""
123
+ toc = self._to_toc("-", "# ") if self.config.with_toc else ""
124
124
  return self._to_metadata_txt() + toc + self._to_body_txt()
125
125
 
126
126
  def _to_body_txt(self) -> str:
@@ -131,13 +131,13 @@ class MdWriter(BaseWriter):
131
131
  if isinstance(section, Chapter):
132
132
  content.append(self._to_chapter_txt(section))
133
133
 
134
- return f"{self.paragraph_separator}".join(content)
134
+ return f"{self.config.paragraph_separator}".join(content)
135
135
 
136
136
  def _to_volume_txt(self, volume) -> str:
137
137
  return (
138
138
  f"# {volume.title}"
139
- + self.paragraph_separator
140
- + self.paragraph_separator.join(
139
+ + self.config.paragraph_separator
140
+ + self.config.paragraph_separator.join(
141
141
  [
142
142
  self._to_chapter_txt(chapter, True)
143
143
  for chapter in volume.chapters
@@ -149,13 +149,13 @@ class MdWriter(BaseWriter):
149
149
  header = "##" if part_of_volume else "#"
150
150
  return (
151
151
  f"{header} {chapter.title}"
152
- + self.paragraph_separator
153
- + self.paragraph_separator.join(chapter.paragraphs)
152
+ + self.config.paragraph_separator
153
+ + self.config.paragraph_separator.join(chapter.paragraphs)
154
154
  )
155
155
 
156
156
  def _to_volume_chapter_txt(self, volume, chapter) -> str:
157
157
  return (
158
158
  f"# {volume.title} {chapter.title}"
159
- + self.paragraph_separator
160
- + self.paragraph_separator.join(chapter.paragraphs)
159
+ + self.config.paragraph_separator
160
+ + self.config.paragraph_separator.join(chapter.paragraphs)
161
161
  )
@@ -66,9 +66,9 @@ class PdfWriter(BaseWriter):
66
66
  pagesize=self._get_pagesize(),
67
67
  title=self.book.title,
68
68
  author=", ".join(self.book.authors),
69
- showBoundary=self.debug,
70
- warnOnMissingFontGlyphs=self.debug,
71
- verbose=self.debug,
69
+ showBoundary=self.config.debug,
70
+ warnOnMissingFontGlyphs=self.config.debug,
71
+ verbose=self.config.debug,
72
72
  )
73
73
 
74
74
  def write(self) -> None:
@@ -165,7 +165,7 @@ class PdfWriter(BaseWriter):
165
165
  self.styles = getSampleStyleSheet()
166
166
  self.styles.add(
167
167
  ParagraphStyle(
168
- name=self.language,
168
+ name=self.config.language,
169
169
  fontName=self.langconf.DEFAULT_PDF_FONT_NAME,
170
170
  fontSize=12,
171
171
  spaceAfter=12,
@@ -202,7 +202,8 @@ class PdfWriter(BaseWriter):
202
202
  for paragraph in chapter.paragraphs:
203
203
  pdf.append(
204
204
  Paragraph(
205
- paragraph.replace("\n", ""), self.styles[self.language]
205
+ paragraph.replace("\n", ""),
206
+ self.styles[self.config.language],
206
207
  )
207
208
  )
208
209
  pdf.append(PageBreak())
@@ -35,12 +35,12 @@ class TxtWriter(BaseWriter):
35
35
  If the input content came from stdin, we'll skip backup and overwrite
36
36
  source text file.
37
37
  """
38
- if self.input_file.name == "<stdin>":
38
+ if self.config.input_file.name == "<stdin>":
39
39
  logger.info("Skip backup source text file as content from stdin")
40
- elif self.split_volume_and_chapter:
40
+ elif self.config.split_volume_and_chapter:
41
41
  self._export_multiple_files()
42
42
  else:
43
- if self.overwrite:
43
+ if self.config.overwrite:
44
44
  self._overwrite_file()
45
45
  else:
46
46
  self._new_file()
@@ -48,7 +48,7 @@ class TxtWriter(BaseWriter):
48
48
  def _export_multiple_files(self) -> None:
49
49
  logger.info("Split multiple files")
50
50
 
51
- txt_filename = Path(self.input_file.name)
51
+ txt_filename = Path(self.config.input_file.name)
52
52
  export_filename = Path(
53
53
  txt_filename.resolve().parent.joinpath(
54
54
  lower_underscore(
@@ -61,7 +61,7 @@ class TxtWriter(BaseWriter):
61
61
  file.write(self._to_metadata_txt())
62
62
 
63
63
  sc_seq = 1
64
- if self.with_toc:
64
+ if self.config.with_toc:
65
65
  export_filename = Path(
66
66
  txt_filename.resolve().parent.joinpath(
67
67
  lower_underscore(
@@ -123,7 +123,7 @@ class TxtWriter(BaseWriter):
123
123
 
124
124
  def _new_file(self) -> None:
125
125
  new_filename = self._output_filename(".txt")
126
- txt_filename = Path(self.input_file.name)
126
+ txt_filename = Path(self.config.input_file.name)
127
127
 
128
128
  if new_filename == txt_filename:
129
129
  ymd_hms = dt.now().strftime("%Y%m%d_%H%M%S")
@@ -142,14 +142,14 @@ class TxtWriter(BaseWriter):
142
142
  logger.info("Generate TXT file: %s", new_filename.resolve())
143
143
 
144
144
  def _overwrite_file(self) -> None:
145
- txt_filename = Path(self.input_file.name)
145
+ txt_filename = Path(self.config.input_file.name)
146
146
 
147
147
  with open(txt_filename, "w", encoding="utf8") as file:
148
148
  file.write(self._to_txt())
149
149
  logger.info("Overwrite txt file: %s", txt_filename.resolve())
150
150
 
151
151
  def _to_txt(self) -> str:
152
- toc = self._to_toc("-") if self.with_toc else ""
152
+ toc = self._to_toc("-") if self.config.with_toc else ""
153
153
  return self._to_metadata_txt() + toc + self._to_body_txt()
154
154
 
155
155
  def _to_body_txt(self) -> str:
@@ -160,13 +160,13 @@ class TxtWriter(BaseWriter):
160
160
  if isinstance(section, Chapter):
161
161
  content.append(self._to_chapter_txt(section))
162
162
 
163
- return f"{self.paragraph_separator}".join(content)
163
+ return f"{self.config.paragraph_separator}".join(content)
164
164
 
165
165
  def _to_volume_txt(self, volume) -> str:
166
166
  return (
167
167
  volume.title
168
- + self.paragraph_separator
169
- + self.paragraph_separator.join(
168
+ + self.config.paragraph_separator
169
+ + self.config.paragraph_separator.join(
170
170
  [self._to_chapter_txt(chapter) for chapter in volume.chapters]
171
171
  )
172
172
  )
@@ -174,8 +174,8 @@ class TxtWriter(BaseWriter):
174
174
  def _to_chapter_txt(self, chapter) -> str:
175
175
  return (
176
176
  chapter.title
177
- + self.paragraph_separator
178
- + self.paragraph_separator.join(chapter.paragraphs)
177
+ + self.config.paragraph_separator
178
+ + self.config.paragraph_separator.join(chapter.paragraphs)
179
179
  )
180
180
 
181
181
  def _to_volume_chapter_txt(self, volume, chapter) -> str:
@@ -183,6 +183,6 @@ class TxtWriter(BaseWriter):
183
183
  volume.title
184
184
  + " "
185
185
  + chapter.title
186
- + self.paragraph_separator
187
- + self.paragraph_separator.join(chapter.paragraphs)
186
+ + self.config.paragraph_separator
187
+ + self.config.paragraph_separator.join(chapter.paragraphs)
188
188
  )
@@ -20,6 +20,7 @@ from txt2ebook.languages.zh_cn import (
20
20
  DEFAULT_RE_CHAPTER,
21
21
  DEFAULT_RE_TAG,
22
22
  DEFAULT_RE_TITLE,
23
+ DEFAULT_RE_TRANSLATOR,
23
24
  DEFAULT_RE_VOLUME,
24
25
  FULLWIDTH_NUMS,
25
26
  HALFWIDTH_NUMS,
@@ -32,12 +33,14 @@ from txt2ebook.languages.zh_cn import (
32
33
  DEFAULT_PDF_FONT_NAME = "AR PL UMing TW"
33
34
  DEFAULT_PDF_FONT_FILE = "uming.ttc"
34
35
  DEFAULT_PDF_FONT_SIZE = 12
36
+ DEFAULT_PDF_PAGE_SIZE = "A5"
35
37
 
36
38
  __all__ = [
37
39
  "DEFAULT_RE_AUTHOR",
38
40
  "DEFAULT_RE_CHAPTER",
39
41
  "DEFAULT_RE_TAG",
40
42
  "DEFAULT_RE_TITLE",
43
+ "DEFAULT_RE_TRANSLATOR",
41
44
  "DEFAULT_RE_VOLUME",
42
45
  "FULLWIDTH_NUMS",
43
46
  "HALFWIDTH_NUMS",
@@ -0,0 +1,31 @@
1
+ #: src/txt2ebook/formats/base.py:94
2
+ msgid "title:"
3
+ msgstr "Title:"
4
+
5
+ #: src/txt2ebook/formats/base.py:95
6
+ msgid "author:"
7
+ msgstr "Author:"
8
+
9
+ #: src/txt2ebook/formats/base.py:96
10
+ msgid "translator:"
11
+ msgstr "Translator:"
12
+
13
+ #: src/txt2ebook/formats/base.py:97
14
+ msgid "tag:"
15
+ msgstr "Tag:"
16
+
17
+ #: src/txt2ebook/formats/base.py:108 src/txt2ebook/formats/gmi.py:59
18
+ #: src/txt2ebook/formats/md.py:58 src/txt2ebook/formats/pdf.py:126
19
+ #: src/txt2ebook/formats/txt.py:68
20
+ msgid "toc"
21
+ msgstr "Table of Content"
22
+
23
+ #: src/txt2ebook/formats/epub.py:144
24
+ msgid "cover"
25
+ msgstr "Cover"
26
+
27
+ #: src/txt2ebook/formats/gmi.py:46 src/txt2ebook/formats/md.py:45
28
+ #: src/txt2ebook/formats/txt.py:55
29
+ msgid "metadata"
30
+ msgstr "Metadata"
31
+
@@ -0,0 +1,31 @@
1
+ #: src/txt2ebook/formats/base.py:94
2
+ msgid "title:"
3
+ msgstr ""
4
+
5
+ #: src/txt2ebook/formats/base.py:95
6
+ msgid "author:"
7
+ msgstr ""
8
+
9
+ #: src/txt2ebook/formats/base.py:96
10
+ msgid "translator:"
11
+ msgstr ""
12
+
13
+ #: src/txt2ebook/formats/base.py:97
14
+ msgid "tag:"
15
+ msgstr ""
16
+
17
+ #: src/txt2ebook/formats/base.py:108 src/txt2ebook/formats/gmi.py:59
18
+ #: src/txt2ebook/formats/md.py:58 src/txt2ebook/formats/pdf.py:126
19
+ #: src/txt2ebook/formats/txt.py:68
20
+ msgid "toc"
21
+ msgstr ""
22
+
23
+ #: src/txt2ebook/formats/epub.py:144
24
+ msgid "cover"
25
+ msgstr ""
26
+
27
+ #: src/txt2ebook/formats/gmi.py:46 src/txt2ebook/formats/md.py:45
28
+ #: src/txt2ebook/formats/txt.py:55
29
+ msgid "metadata"
30
+ msgstr ""
31
+