txt2ebook 0.1.83__tar.gz → 0.1.87__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 (45) hide show
  1. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/PKG-INFO +13 -9
  2. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/README.md +11 -7
  3. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/pyproject.toml +3 -1
  4. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/__init__.py +1 -1
  5. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/formats/tex.py +67 -12
  6. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/languages/en.py +1 -0
  7. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/languages/zh_cn.py +1 -0
  8. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/languages/zh_tw.py +2 -0
  9. txt2ebook-0.1.87/src/txt2ebook/locales/en/LC_MESSAGES/txt2ebook.po +31 -0
  10. txt2ebook-0.1.87/src/txt2ebook/locales/txt2ebook.pot +31 -0
  11. txt2ebook-0.1.87/src/txt2ebook/locales/zh-cn/LC_MESSAGES/txt2ebook.po +31 -0
  12. txt2ebook-0.1.87/src/txt2ebook/locales/zh-tw/LC_MESSAGES/txt2ebook.po +31 -0
  13. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/models/book.py +1 -0
  14. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/parser.py +15 -3
  15. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/tokenizer.py +4 -2
  16. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/txt2ebook.py +9 -0
  17. txt2ebook-0.1.83/src/txt2ebook/locales/en/LC_MESSAGES/txt2ebook.po +0 -34
  18. txt2ebook-0.1.83/src/txt2ebook/locales/txt2ebook.pot +0 -34
  19. txt2ebook-0.1.83/src/txt2ebook/locales/zh-cn/LC_MESSAGES/txt2ebook.po +0 -34
  20. txt2ebook-0.1.83/src/txt2ebook/locales/zh-tw/LC_MESSAGES/txt2ebook.po +0 -34
  21. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/LICENSE.md +0 -0
  22. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/__main__.py +0 -0
  23. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/exceptions.py +0 -0
  24. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/formats/__init__.py +0 -0
  25. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/formats/base.py +0 -0
  26. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/formats/epub.py +0 -0
  27. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/formats/gmi.py +0 -0
  28. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/formats/md.py +0 -0
  29. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/formats/pdf.py +0 -0
  30. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/formats/templates/__init__.py +0 -0
  31. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/formats/templates/epub/__init__.py +0 -0
  32. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/formats/templates/epub/clean.css +0 -0
  33. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/formats/templates/epub/condense.css +0 -0
  34. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/formats/templates/epub/noindent.css +0 -0
  35. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/formats/txt.py +0 -0
  36. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/formats/typ.py +0 -0
  37. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/helpers/__init__.py +0 -0
  38. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/languages/__init__.py +0 -0
  39. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/locales/en/LC_MESSAGES/txt2ebook.mo +0 -0
  40. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/locales/zh-cn/LC_MESSAGES/txt2ebook.mo +0 -0
  41. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/locales/zh-tw/LC_MESSAGES/txt2ebook.mo +0 -0
  42. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/models/__init__.py +0 -0
  43. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/models/chapter.py +0 -0
  44. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/src/txt2ebook/models/volume.py +0 -0
  45. {txt2ebook-0.1.83 → txt2ebook-0.1.87}/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.83
3
+ Version: 0.1.87
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
@@ -19,8 +19,8 @@ Classifier: Programming Language :: Python :: 3.8
19
19
  Classifier: Programming Language :: Python :: 3.9
20
20
  Classifier: Programming Language :: Python :: 3.10
21
21
  Classifier: Programming Language :: Python :: 3.11
22
- Classifier: Programming Language :: Python :: 3 :: Only
23
22
  Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3 :: Only
24
24
  Classifier: Topic :: Text Processing
25
25
  Classifier: Topic :: Text Processing :: Filters
26
26
  Classifier: Topic :: Text Processing :: General
@@ -73,14 +73,16 @@ txt2ebook --help
73
73
  ```
74
74
 
75
75
  ```console
76
+
76
77
  usage: txt2ebook [-of OUTPUT_FOLDER] [-p] [-f {epub,gmi,md,pdf,tex,txt,typ}]
77
- [-t TITLE] [-l LANGUAGE] [-a AUTHOR] [-tr TRANSLATOR]
78
- [-c IMAGE_FILENAME] [-w WIDTH] [-ff FILENAME_FORMAT]
79
- [-ps SEPARATOR] [-pz PAGE_SIZE] [-rd REGEX] [-rvc REGEX]
80
- [-rv REGEX] [-rc REGEX] [-rt REGEX] [-ra REGEX] [-rl REGEX]
81
- [-rr REGEX REGEX] [-et {clean,condense,noindent}] [-vp] [-tp]
82
- [-sp] [-ss] [-toc] [-hn] [-fw] [-rw] [-ow] [-op] [-q] [-v]
83
- [-y] [-d] [--env] [-h] [-V]
78
+ [-ik INDEX_KEYWORD] [-t TITLE] [-l LANGUAGE] [-a AUTHOR]
79
+ [-tr TRANSLATOR] [-c IMAGE_FILENAME] [-w WIDTH]
80
+ [-ff FILENAME_FORMAT] [-ps SEPARATOR] [-pz PAGE_SIZE]
81
+ [-rd REGEX] [-rvc REGEX] [-rv REGEX] [-rc REGEX] [-rt REGEX]
82
+ [-ra REGEX] [-rl REGEX] [-rr REGEX REGEX]
83
+ [-et {clean,condense,noindent}] [-vp] [-tp] [-sp] [-ss]
84
+ [-toc] [-hn] [-fw] [-rw] [-ow] [-op] [-q] [-v] [-y] [-d]
85
+ [--env] [-h] [-V]
84
86
  TXT_FILENAME [EBOOK_FILENAME]
85
87
 
86
88
  txt2ebook/tte is a cli tool to convert txt file to ebook format.
@@ -102,6 +104,8 @@ optional arguments:
102
104
  remove converted ebooks specified by --output-folder option (default: 'False')
103
105
  -f {epub,gmi,md,pdf,tex,txt,typ}, --format {epub,gmi,md,pdf,tex,txt,typ}
104
106
  ebook format (default: 'epub')
107
+ -ik INDEX_KEYWORD, --index-keyword INDEX_KEYWORD
108
+ keyword to index (default: '[]')
105
109
  -t TITLE, --title TITLE
106
110
  title of the ebook (default: 'None')
107
111
  -l LANGUAGE, --language LANGUAGE
@@ -31,14 +31,16 @@ txt2ebook --help
31
31
  ```
32
32
 
33
33
  ```console
34
+
34
35
  usage: txt2ebook [-of OUTPUT_FOLDER] [-p] [-f {epub,gmi,md,pdf,tex,txt,typ}]
35
- [-t TITLE] [-l LANGUAGE] [-a AUTHOR] [-tr TRANSLATOR]
36
- [-c IMAGE_FILENAME] [-w WIDTH] [-ff FILENAME_FORMAT]
37
- [-ps SEPARATOR] [-pz PAGE_SIZE] [-rd REGEX] [-rvc REGEX]
38
- [-rv REGEX] [-rc REGEX] [-rt REGEX] [-ra REGEX] [-rl REGEX]
39
- [-rr REGEX REGEX] [-et {clean,condense,noindent}] [-vp] [-tp]
40
- [-sp] [-ss] [-toc] [-hn] [-fw] [-rw] [-ow] [-op] [-q] [-v]
41
- [-y] [-d] [--env] [-h] [-V]
36
+ [-ik INDEX_KEYWORD] [-t TITLE] [-l LANGUAGE] [-a AUTHOR]
37
+ [-tr TRANSLATOR] [-c IMAGE_FILENAME] [-w WIDTH]
38
+ [-ff FILENAME_FORMAT] [-ps SEPARATOR] [-pz PAGE_SIZE]
39
+ [-rd REGEX] [-rvc REGEX] [-rv REGEX] [-rc REGEX] [-rt REGEX]
40
+ [-ra REGEX] [-rl REGEX] [-rr REGEX REGEX]
41
+ [-et {clean,condense,noindent}] [-vp] [-tp] [-sp] [-ss]
42
+ [-toc] [-hn] [-fw] [-rw] [-ow] [-op] [-q] [-v] [-y] [-d]
43
+ [--env] [-h] [-V]
42
44
  TXT_FILENAME [EBOOK_FILENAME]
43
45
 
44
46
  txt2ebook/tte is a cli tool to convert txt file to ebook format.
@@ -60,6 +62,8 @@ optional arguments:
60
62
  remove converted ebooks specified by --output-folder option (default: 'False')
61
63
  -f {epub,gmi,md,pdf,tex,txt,typ}, --format {epub,gmi,md,pdf,tex,txt,typ}
62
64
  ebook format (default: 'epub')
65
+ -ik INDEX_KEYWORD, --index-keyword INDEX_KEYWORD
66
+ keyword to index (default: '[]')
63
67
  -t TITLE, --title TITLE
64
68
  title of the ebook (default: 'None')
65
69
  -l LANGUAGE, --language LANGUAGE
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "txt2ebook"
3
- version = "0.1.83"
3
+ version = "0.1.87"
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"
@@ -65,6 +65,8 @@ tte = 'txt2ebook.txt2ebook:main'
65
65
  babel = "^2.12.1"
66
66
  scripttest = "^1.3"
67
67
  flake8-simplify = "^0.21.0"
68
+ nox = "^2024.4.15"
69
+ nox-poetry = "^1.0.3"
68
70
 
69
71
  [build-system]
70
72
  build-backend = "poetry.core.masonry.api"
@@ -22,7 +22,7 @@ import sys
22
22
 
23
23
  logger = logging.getLogger(__name__)
24
24
 
25
- __version__ = "0.1.83"
25
+ __version__ = "0.1.87"
26
26
 
27
27
 
28
28
  def setup_logger(config: argparse.Namespace) -> None:
@@ -26,8 +26,7 @@ from pylatex import Document as Doc
26
26
  from pylatex import NoEscape as NoEsc
27
27
  from pylatex import Package as Pkg
28
28
  from pylatex.section import Chapter as Chap
29
- from pylatex.section import Paragraph as Par
30
- from pylatex.section import Part as Part
29
+ from pylatex.section import Part
31
30
 
32
31
  from txt2ebook.formats.base import BaseWriter
33
32
  from txt2ebook.models import Chapter, Volume
@@ -53,6 +52,35 @@ class TexWriter(BaseWriter):
53
52
  doc = Doc(documentclass="ctexbook", document_options=[self._fontset()])
54
53
 
55
54
  doc.packages.append(Pkg("geometry", options=["a6paper"]))
55
+ doc.packages.append(Pkg("makeidx"))
56
+ doc.packages.append(
57
+ Pkg(
58
+ "idxlayout",
59
+ options=[
60
+ "columns=1",
61
+ "font=footnotesize",
62
+ "itemlayout=singlepar",
63
+ "indentunit=0pt",
64
+ ],
65
+ )
66
+ )
67
+ doc.packages.append(
68
+ Pkg("hyperref", options=["colorlinks=true", "linktocpage=true"])
69
+ )
70
+
71
+ doc.packages.append(Pkg("tocloft", options=["titles"]))
72
+ tocloft = NoEsc(
73
+ r"""
74
+ \renewcommand{\cftbeforepartskip}{1em}
75
+ \renewcommand{\cftbeforechapskip}{0em}
76
+ \renewcommand{\cftpartfont}{\normalfont\bfseries}
77
+ \renewcommand{\cftchapfont}{\normalfont}
78
+ \renewcommand{\cftchapleader}{\dotfill}
79
+ \renewcommand{\cftpartpagefont}{\small\bfseries}
80
+ \renewcommand{\cftchappagefont}{\small\bfseries}
81
+ """
82
+ )
83
+ doc.preamble.append(tocloft)
56
84
 
57
85
  hide_section_seq = (
58
86
  r"chapter/name={},chapter/number={},part/name={},part/number={}"
@@ -60,36 +88,63 @@ class TexWriter(BaseWriter):
60
88
  doc.preamble.append(Cmd("ctexset", NoEsc(hide_section_seq)))
61
89
  doc.preamble.append(Cmd("title", self.book.title))
62
90
  doc.preamble.append(Cmd("author", ", ".join(self.book.authors)))
63
- doc.preamble.append(Cmd("date", NoEsc(r"\today")))
91
+ doc.preamble.append(NoEsc(r"\date{}"))
92
+ doc.preamble.append(Cmd("makeindex"))
64
93
 
65
94
  doc.append(NoEsc(r"\maketitle"))
66
95
  doc.append(NoEsc(r"\thispagestyle{empty}"))
96
+ doc.append(NoEsc(r"\addtocontents{toc}{\protect\pagestyle{empty}}"))
97
+ doc.append(
98
+ NoEsc(r"\addtocontents{toc}{\protect\thispagestyle{empty}}")
99
+ )
100
+ doc.append(NoEsc(r"\tableofcontents"))
101
+ doc.append(NoEsc(r"\pagestyle{empty}"))
102
+ doc.append(NoEsc(r"\cleardoublepage"))
103
+ doc.append(NoEsc(r"\pagenumbering{arabic}"))
104
+ doc.append(NoEsc(r"\pagestyle{headings}"))
67
105
 
68
106
  for section in self.book.toc:
69
107
  if isinstance(section, Volume):
70
- with doc.create(Part(section.title)):
108
+ with doc.create(Part(section.title, label=False)):
71
109
  for chapter in section.chapters:
72
- with doc.create(Chap(chapter.title)):
110
+ with doc.create(Chap(chapter.title, label=False)):
73
111
  for paragraph in chapter.paragraphs:
74
- doc.append(Par(paragraph.replace("\n", "")))
112
+ par = self._process_paragraph(paragraph)
113
+ doc.append(NoEsc(rf"\par{{{par}}}"))
114
+
75
115
  if isinstance(section, Chapter):
76
- with doc.create(Chap(section.title)):
116
+ with doc.create(Chap(section.title, label=False)):
77
117
  for paragraph in section.paragraphs:
78
- doc.append(Par(paragraph.replace("\n", "")))
118
+ par = self._process_paragraph(paragraph)
119
+ doc.append(NoEsc(rf"\par{{{par}}}"))
120
+
121
+ doc.append(Cmd("printindex"))
79
122
 
80
123
  filename = str(new_filename.parent / new_filename.stem)
81
124
  pdf_filename = Path(filename).with_suffix(".pdf")
82
- doc.generate_pdf(filename, compiler="xelatex", clean_tex=False)
125
+ doc.generate_pdf(filename, compiler="latexmk", clean_tex=False)
83
126
 
84
127
  if self.config.open:
85
128
  self._open_file(pdf_filename)
86
129
 
130
+ def _process_paragraph(self, paragraph) -> str:
131
+ par = paragraph.strip()
132
+ for keyword in self.config.index_keyword:
133
+ par = par.replace(keyword, rf"\index{{{keyword}}}")
134
+
135
+ for keyword in self.book.index:
136
+ par = par.replace(keyword, rf"\index{{{keyword}}}")
137
+
138
+ return par
139
+
87
140
  def _fontset(self) -> str:
88
141
  if sys.platform == "linux":
89
- return "fontset = ubuntu"
142
+ return "fontset=ubuntu"
90
143
 
91
144
  if sys.platform == "darwin":
92
- return "fontset = macos"
145
+ return "fontset=macos"
93
146
 
94
147
  if sys.platform == "windows":
95
- return "fontset = windows"
148
+ return "fontset=windows"
149
+
150
+ return "fontset=ubuntu"
@@ -18,5 +18,6 @@
18
18
  DEFAULT_RE_TITLE = r"Title:(.*)"
19
19
  DEFAULT_RE_AUTHOR = r"Author:(.*)"
20
20
  DEFAULT_RE_TAG = r"Tags:(.*)"
21
+ DEFAULT_RE_INDEX = r"Index:(.*)"
21
22
  DEFAULT_RE_VOLUME = r"(Volume.*)"
22
23
  DEFAULT_RE_CHAPTER = r"(Chapter.*)"
@@ -52,6 +52,7 @@ RE_CHAPTERS = [
52
52
  DEFAULT_RE_AUTHOR = r"作者:(.*)"
53
53
  DEFAULT_RE_CHAPTER = "(" + "|".join(RE_CHAPTERS) + ")"
54
54
  DEFAULT_RE_TAG = r"标签:(.*)"
55
+ DEFAULT_RE_INDEX = r"索引:(.*)"
55
56
  DEFAULT_RE_TITLE = r"书名:(.*)"
56
57
  DEFAULT_RE_TRANSLATOR = r"翻译:(.*)"
57
58
  DEFAULT_RE_VOLUME = "(" + "|".join(RE_VOLUMES) + ")"
@@ -18,6 +18,7 @@
18
18
  from txt2ebook.languages.zh_cn import (
19
19
  DEFAULT_RE_AUTHOR,
20
20
  DEFAULT_RE_CHAPTER,
21
+ DEFAULT_RE_INDEX,
21
22
  DEFAULT_RE_TAG,
22
23
  DEFAULT_RE_TITLE,
23
24
  DEFAULT_RE_TRANSLATOR,
@@ -39,6 +40,7 @@ __all__ = [
39
40
  "DEFAULT_RE_AUTHOR",
40
41
  "DEFAULT_RE_CHAPTER",
41
42
  "DEFAULT_RE_TAG",
43
+ "DEFAULT_RE_INDEX",
42
44
  "DEFAULT_RE_TITLE",
43
45
  "DEFAULT_RE_TRANSLATOR",
44
46
  "DEFAULT_RE_VOLUME",
@@ -0,0 +1,31 @@
1
+ #: src/txt2ebook/formats/base.py:141
2
+ msgid "title:"
3
+ msgstr "Title:"
4
+
5
+ #: src/txt2ebook/formats/base.py:142
6
+ msgid "author:"
7
+ msgstr "Author:"
8
+
9
+ #: src/txt2ebook/formats/base.py:143
10
+ msgid "translator:"
11
+ msgstr "Translator:"
12
+
13
+ #: src/txt2ebook/formats/base.py:144
14
+ msgid "tag:"
15
+ msgstr "Tag:"
16
+
17
+ #: src/txt2ebook/formats/base.py:155 src/txt2ebook/formats/gmi.py:62
18
+ #: src/txt2ebook/formats/md.py:61 src/txt2ebook/formats/pdf.py:130
19
+ #: src/txt2ebook/formats/txt.py:71
20
+ msgid "toc"
21
+ msgstr "Table of Content"
22
+
23
+ #: src/txt2ebook/formats/epub.py:147
24
+ msgid "cover"
25
+ msgstr "Cover"
26
+
27
+ #: src/txt2ebook/formats/gmi.py:47 src/txt2ebook/formats/md.py:46
28
+ #: src/txt2ebook/formats/txt.py:56
29
+ msgid "metadata"
30
+ msgstr "Metadata"
31
+
@@ -0,0 +1,31 @@
1
+ #: src/txt2ebook/formats/base.py:141
2
+ msgid "title:"
3
+ msgstr ""
4
+
5
+ #: src/txt2ebook/formats/base.py:142
6
+ msgid "author:"
7
+ msgstr ""
8
+
9
+ #: src/txt2ebook/formats/base.py:143
10
+ msgid "translator:"
11
+ msgstr ""
12
+
13
+ #: src/txt2ebook/formats/base.py:144
14
+ msgid "tag:"
15
+ msgstr ""
16
+
17
+ #: src/txt2ebook/formats/base.py:155 src/txt2ebook/formats/gmi.py:62
18
+ #: src/txt2ebook/formats/md.py:61 src/txt2ebook/formats/pdf.py:130
19
+ #: src/txt2ebook/formats/txt.py:71
20
+ msgid "toc"
21
+ msgstr ""
22
+
23
+ #: src/txt2ebook/formats/epub.py:147
24
+ msgid "cover"
25
+ msgstr ""
26
+
27
+ #: src/txt2ebook/formats/gmi.py:47 src/txt2ebook/formats/md.py:46
28
+ #: src/txt2ebook/formats/txt.py:56
29
+ msgid "metadata"
30
+ msgstr ""
31
+
@@ -0,0 +1,31 @@
1
+ #: src/txt2ebook/formats/base.py:141
2
+ msgid "title:"
3
+ msgstr "书名:"
4
+
5
+ #: src/txt2ebook/formats/base.py:142
6
+ msgid "author:"
7
+ msgstr "作者:"
8
+
9
+ #: src/txt2ebook/formats/base.py:143
10
+ msgid "translator:"
11
+ msgstr "翻译:"
12
+
13
+ #: src/txt2ebook/formats/base.py:144
14
+ msgid "tag:"
15
+ msgstr "票签:"
16
+
17
+ #: src/txt2ebook/formats/base.py:155 src/txt2ebook/formats/gmi.py:62
18
+ #: src/txt2ebook/formats/md.py:61 src/txt2ebook/formats/pdf.py:130
19
+ #: src/txt2ebook/formats/txt.py:71
20
+ msgid "toc"
21
+ msgstr "目录"
22
+
23
+ #: src/txt2ebook/formats/epub.py:147
24
+ msgid "cover"
25
+ msgstr "封面"
26
+
27
+ #: src/txt2ebook/formats/gmi.py:47 src/txt2ebook/formats/md.py:46
28
+ #: src/txt2ebook/formats/txt.py:56
29
+ msgid "metadata"
30
+ msgstr "元数据"
31
+
@@ -0,0 +1,31 @@
1
+ #: src/txt2ebook/formats/base.py:141
2
+ msgid "title:"
3
+ msgstr "书名:"
4
+
5
+ #: src/txt2ebook/formats/base.py:142
6
+ msgid "author:"
7
+ msgstr "作者:"
8
+
9
+ #: src/txt2ebook/formats/base.py:143
10
+ msgid "translator:"
11
+ msgstr "翻译:"
12
+
13
+ #: src/txt2ebook/formats/base.py:144
14
+ msgid "tag:"
15
+ msgstr "标签:"
16
+
17
+ #: src/txt2ebook/formats/base.py:155 src/txt2ebook/formats/gmi.py:62
18
+ #: src/txt2ebook/formats/md.py:61 src/txt2ebook/formats/pdf.py:130
19
+ #: src/txt2ebook/formats/txt.py:71
20
+ msgid "toc"
21
+ msgstr "目录"
22
+
23
+ #: src/txt2ebook/formats/epub.py:147
24
+ msgid "cover"
25
+ msgstr "封面"
26
+
27
+ #: src/txt2ebook/formats/gmi.py:47 src/txt2ebook/formats/md.py:46
28
+ #: src/txt2ebook/formats/txt.py:56
29
+ msgid "metadata"
30
+ msgstr "元数据"
31
+
@@ -36,6 +36,7 @@ class Book:
36
36
  authors: List[str] = field(default_factory=lambda: [])
37
37
  translators: List[str] = field(default_factory=lambda: [])
38
38
  tags: List[str] = field(default_factory=lambda: [])
39
+ index: List[str] = field(default_factory=lambda: [])
39
40
  language: str = field(default="")
40
41
  cover: str = field(default="", repr=False)
41
42
  raw_content: str = field(default="", repr=False)
@@ -55,13 +55,17 @@ class Parser:
55
55
  massaged_content = self.massage()
56
56
  tokenizer = Tokenizer(massaged_content, self.config)
57
57
 
58
- (book_title, authors, tags, toc) = self.parse_tokens(tokenizer)
58
+ (book_title, authors, translators, tags, index, toc) = (
59
+ self.parse_tokens(tokenizer)
60
+ )
59
61
 
60
62
  book = Book(
61
63
  title=book_title,
62
64
  language=self.config.language,
63
65
  authors=authors,
66
+ translators=translators,
64
67
  tags=tags,
68
+ index=index,
65
69
  cover=self.config.cover,
66
70
  raw_content=self.raw_content,
67
71
  massaged_content=massaged_content,
@@ -126,6 +130,7 @@ class Parser:
126
130
  book_title = ""
127
131
  authors = []
128
132
  tags = []
133
+ index = []
129
134
  translators = []
130
135
  current_volume = Volume("")
131
136
  current_chapter = Chapter("")
@@ -163,6 +168,9 @@ class Parser:
163
168
  if token.type == "TAG":
164
169
  tags.append(token.value)
165
170
 
171
+ if token.type == "INDEX":
172
+ index = token.value.split(" ")
173
+
166
174
  if token.type == "TRANSLATOR":
167
175
  translators.append(token.value)
168
176
 
@@ -216,15 +224,19 @@ class Parser:
216
224
  if self.config.title:
217
225
  book_title = self.config.title
218
226
 
227
+ if self.config.translator:
228
+ authors = self.config.translator
229
+
219
230
  logger.info("Found or set book title: %s", book_title)
220
231
  logger.info("Found or set authors: %s", repr(authors))
221
- logger.info("Found or set categories: %s", repr(tags))
222
232
  logger.info("Found or set translators: %s", repr(translators))
233
+ logger.info("Found or set tags: %s", repr(tags))
234
+ logger.info("Found or set index: %s", repr(index))
223
235
 
224
236
  if self.config.sort_volume_and_chapter:
225
237
  self.sort_volume_and_chapter(toc)
226
238
 
227
- return (book_title, authors, tags, toc)
239
+ return (book_title, authors, translators, tags, index, toc)
228
240
 
229
241
  def sort_volume_and_chapter(self, toc: List) -> None:
230
242
  """Sort by title of volumes and its chapters.
@@ -129,6 +129,7 @@ class Tokenizer:
129
129
  ("TITLE", re_title),
130
130
  ("AUTHOR", re_author),
131
131
  ("TAG", f"{self.langconf.DEFAULT_RE_TAG}"),
132
+ ("INDEX", f"{self.langconf.DEFAULT_RE_INDEX}"),
132
133
  ("TRANSLATOR", f"{self.langconf.DEFAULT_RE_TRANSLATOR}"),
133
134
  ]
134
135
 
@@ -151,8 +152,9 @@ class Tokenizer:
151
152
  2 书名:
152
153
  3 作者:
153
154
  4 标签:
154
- 5 翻译:
155
- 6 ---
155
+ 5 索引:
156
+ 6 翻译:
157
+ 7 ---
156
158
 
157
159
  """
158
160
  match = re.search(
@@ -155,6 +155,15 @@ def build_parser(
155
155
  help="ebook format (default: 'epub')",
156
156
  )
157
157
 
158
+ parser.add_argument(
159
+ "-ik",
160
+ "--index-keyword",
161
+ dest="index_keyword",
162
+ action="append",
163
+ default=[],
164
+ help="keyword to index (default: '%(default)s')",
165
+ )
166
+
158
167
  parser.add_argument(
159
168
  "-t",
160
169
  "--title",
@@ -1,34 +0,0 @@
1
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:141
2
- msgid "title:"
3
- msgstr "Title:"
4
-
5
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:142
6
- msgid "author:"
7
- msgstr "Author:"
8
-
9
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:143
10
- msgid "translator:"
11
- msgstr "Translator:"
12
-
13
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:144
14
- msgid "tag:"
15
- msgstr "Tag:"
16
-
17
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:155
18
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/gmi.py:62
19
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/md.py:61
20
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/pdf.py:130
21
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/txt.py:71
22
- msgid "toc"
23
- msgstr "Table of Content"
24
-
25
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/epub.py:147
26
- msgid "cover"
27
- msgstr "Cover"
28
-
29
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/gmi.py:47
30
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/md.py:46
31
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/txt.py:56
32
- msgid "metadata"
33
- msgstr "Metadata"
34
-
@@ -1,34 +0,0 @@
1
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:141
2
- msgid "title:"
3
- msgstr ""
4
-
5
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:142
6
- msgid "author:"
7
- msgstr ""
8
-
9
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:143
10
- msgid "translator:"
11
- msgstr ""
12
-
13
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:144
14
- msgid "tag:"
15
- msgstr ""
16
-
17
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:155
18
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/gmi.py:62
19
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/md.py:61
20
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/pdf.py:130
21
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/txt.py:71
22
- msgid "toc"
23
- msgstr ""
24
-
25
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/epub.py:147
26
- msgid "cover"
27
- msgstr ""
28
-
29
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/gmi.py:47
30
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/md.py:46
31
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/txt.py:56
32
- msgid "metadata"
33
- msgstr ""
34
-
@@ -1,34 +0,0 @@
1
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:141
2
- msgid "title:"
3
- msgstr "书名:"
4
-
5
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:142
6
- msgid "author:"
7
- msgstr "作者:"
8
-
9
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:143
10
- msgid "translator:"
11
- msgstr "翻译:"
12
-
13
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:144
14
- msgid "tag:"
15
- msgstr "票签:"
16
-
17
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:155
18
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/gmi.py:62
19
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/md.py:61
20
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/pdf.py:130
21
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/txt.py:71
22
- msgid "toc"
23
- msgstr "目录"
24
-
25
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/epub.py:147
26
- msgid "cover"
27
- msgstr "封面"
28
-
29
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/gmi.py:47
30
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/md.py:46
31
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/txt.py:56
32
- msgid "metadata"
33
- msgstr "元数据"
34
-
@@ -1,34 +0,0 @@
1
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:141
2
- msgid "title:"
3
- msgstr "书名:"
4
-
5
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:142
6
- msgid "author:"
7
- msgstr "作者:"
8
-
9
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:143
10
- msgid "translator:"
11
- msgstr "翻译:"
12
-
13
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:144
14
- msgid "tag:"
15
- msgstr "标签:"
16
-
17
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/base.py:155
18
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/gmi.py:62
19
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/md.py:61
20
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/pdf.py:130
21
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/txt.py:71
22
- msgid "toc"
23
- msgstr "目录"
24
-
25
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/epub.py:147
26
- msgid "cover"
27
- msgstr "封面"
28
-
29
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/gmi.py:47
30
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/md.py:46
31
- #: /home/ang/src/self/txt2ebook/txt2ebook/src/txt2ebook/formats/txt.py:56
32
- msgid "metadata"
33
- msgstr "元数据"
34
-
File without changes