intellireading-cli 2.1.2__tar.gz → 2.2.0__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.
- {intellireading_cli-2.1.2 → intellireading_cli-2.2.0}/PKG-INFO +63 -6
- {intellireading_cli-2.1.2 → intellireading_cli-2.2.0}/README.md +62 -5
- {intellireading_cli-2.1.2 → intellireading_cli-2.2.0}/pyproject.toml +1 -1
- intellireading_cli-2.2.0/src/intellireading/client/__about_cli__.py +1 -0
- {intellireading_cli-2.1.2 → intellireading_cli-2.2.0}/src/intellireading/client/__init__.py +6 -0
- {intellireading_cli-2.1.2 → intellireading_cli-2.2.0}/src/intellireading/client/commands.py +121 -7
- intellireading_cli-2.2.0/src/intellireading/client/metaguiding.py +1428 -0
- intellireading_cli-2.1.2/src/intellireading/client/__about_cli__.py +0 -1
- intellireading_cli-2.1.2/src/intellireading/client/metaguiding.py +0 -525
- {intellireading_cli-2.1.2 → intellireading_cli-2.2.0}/.gitignore +0 -0
- {intellireading_cli-2.1.2 → intellireading_cli-2.2.0}/LICENSE +0 -0
- {intellireading_cli-2.1.2 → intellireading_cli-2.2.0}/src/intellireading/__init__.py +0 -0
- {intellireading_cli-2.1.2 → intellireading_cli-2.2.0}/src/intellireading/client/__main__.py +0 -0
- {intellireading_cli-2.1.2 → intellireading_cli-2.2.0}/src/intellireading/client/app.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: intellireading-cli
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.0
|
|
4
4
|
Summary: Intellireading-cli is a Python library with a set of tools to improve your reading experience
|
|
5
5
|
Project-URL: Documentation, https://go.hugobatista.com/gh/intellireading-cli#readme
|
|
6
6
|
Project-URL: Issues, https://go.hugobatista.com/gh/intellireading-cli/issues
|
|
@@ -153,6 +153,54 @@ To metaguide all files in a directory, use the `metaguide-dir` command. The comm
|
|
|
153
153
|
> intellireading metaguide-dir --input_dir mydir --output_dir mydir_metaguided
|
|
154
154
|
```
|
|
155
155
|
|
|
156
|
+
#### Control the fixation level
|
|
157
|
+
The `--fixation` option controls how much of each word is bolded. It accepts values from `1` (least bold) to `5` (most bold) and defaults to `3`, which is the historical behaviour of IntelliReading.
|
|
158
|
+
|
|
159
|
+
The option is available on `metaguide-epub`, `metaguide-xhtml`, and `metaguide-dir`:
|
|
160
|
+
|
|
161
|
+
```console
|
|
162
|
+
> intellireading metaguide-epub --input_file mybook.epub --output_file mybook_metaguided.epub --fixation 5
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The public contract is the range `1`–`5`, the default `3`, and the fact that higher levels never bold less of each word (and usually bold more). The exact split point for each word is an implementation detail and may change.
|
|
166
|
+
|
|
167
|
+
The fixation level only applies to new conversions. EPUB files that are already metaguided are copied unchanged. To apply a different level to an already metaguided EPUB, use `--remove_metaguiding` first and then metaguide the result again. Standalone XHTML files have no metaguided marker, so avoid running metaguiding twice on the same XHTML file.
|
|
168
|
+
|
|
169
|
+
#### Control the bold style
|
|
170
|
+
The `--bold_style` option controls how the bold part of each word is rendered. It accepts:
|
|
171
|
+
|
|
172
|
+
- `tag` (default) — uses `<b>` and the font's real bold face;
|
|
173
|
+
- `shadow` — uses `<b class="ir-bold">` plus a CSS `text-shadow`, which keeps the original font metrics;
|
|
174
|
+
- `stroke` — uses `<b class="ir-bold">` plus a CSS `-webkit-text-stroke`, which also keeps the original font metrics.
|
|
175
|
+
|
|
176
|
+
The visual modes (`shadow` and `stroke`) are intended for Kobo kepubs and other WebKit-based readers. They avoid the page count changes that real bold can cause on Kobo, because the text keeps the same width and line breaks. On readers that do not support those CSS properties, the text may render without emphasis; use `tag` for maximum compatibility.
|
|
177
|
+
|
|
178
|
+
The option is available on `metaguide-epub`, `metaguide-xhtml`, and `metaguide-dir`:
|
|
179
|
+
|
|
180
|
+
```console
|
|
181
|
+
> intellireading metaguide-epub --input_file mybook.epub --output_file mybook_metaguided.epub --bold_style shadow
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
#### Control the bold intensity
|
|
185
|
+
The `--bold_intensity` option controls how strong the visual bold effect is when `--bold_style` is `shadow` or `stroke`. It accepts values from `1` (subtle) to `5` (strongest) and defaults to `3`.
|
|
186
|
+
|
|
187
|
+
```console
|
|
188
|
+
> intellireading metaguide-epub --input_file mybook.epub --output_file mybook_metaguided.epub --bold_style shadow --bold_intensity 5
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
The intensity only affects the visual modes. With `--bold_style tag` the option is ignored, because the real bold face is used.
|
|
192
|
+
|
|
193
|
+
#### What gets metaguided
|
|
194
|
+
Metaguiding only changes prose text inside the document body. The following content is preserved byte-for-byte:
|
|
195
|
+
|
|
196
|
+
- `<style>` and `<script>` elements (CSS and JavaScript)
|
|
197
|
+
- `<pre>` and `<code>` elements (preformatted text and code samples)
|
|
198
|
+
- `<text>` and `<tspan>` elements in SVG
|
|
199
|
+
- CDATA sections
|
|
200
|
+
- HTML comments
|
|
201
|
+
|
|
202
|
+
This keeps stylesheets, scripts and embedded SVG content valid. Elements that are not listed above (for example MathML text elements or `<textarea>`) are still metaguided, so bold tags may be inserted into them. Removal of metaguiding keeps its previous behaviour and can still clean up bold tags added to these regions by older versions.
|
|
203
|
+
|
|
156
204
|
## Experimental Features
|
|
157
205
|
Some features are still experimental and may not work as expected. Use them with caution.
|
|
158
206
|
|
|
@@ -207,7 +255,7 @@ metaguide_xhtml_file("input.html", "output.html")
|
|
|
207
255
|
|
|
208
256
|
#### EPUB Functions
|
|
209
257
|
|
|
210
|
-
**`metaguide_epub_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False)`**
|
|
258
|
+
**`metaguide_epub_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False, fixation: int = 3, bold_style: str = "tag", bold_intensity: int = 3)`**
|
|
211
259
|
|
|
212
260
|
Metaguides an EPUB file by applying visual anchoring to text content within all XHTML files in the EPUB.
|
|
213
261
|
|
|
@@ -217,11 +265,20 @@ from intellireading.client import metaguide_epub_file
|
|
|
217
265
|
# Basic metaguiding
|
|
218
266
|
metaguide_epub_file("mybook.epub", "mybook_metaguided.epub")
|
|
219
267
|
|
|
268
|
+
# Bold more of each word (levels go from 1 to 5, default is 3)
|
|
269
|
+
metaguide_epub_file("mybook.epub", "mybook_metaguided.epub", fixation=5)
|
|
270
|
+
|
|
271
|
+
# Use visual bold (keeps the original font metrics and page count on Kobo kepubs)
|
|
272
|
+
metaguide_epub_file("mybook.epub", "mybook_metaguided.epub", bold_style="shadow")
|
|
273
|
+
|
|
274
|
+
# Use a stronger visual bold effect (intensity goes from 1 to 5, default is 3)
|
|
275
|
+
metaguide_epub_file("mybook.epub", "mybook_metaguided.epub", bold_style="shadow", bold_intensity=5)
|
|
276
|
+
|
|
220
277
|
# Remove metaguiding (experimental)
|
|
221
278
|
metaguide_epub_file("mybook_metaguided.epub", "mybook_original.epub", remove_metaguiding=True)
|
|
222
279
|
```
|
|
223
280
|
|
|
224
|
-
**`metaguide_epub_stream(input_stream: BytesIO, *, remove_metaguiding: bool = False) -> BytesIO`**
|
|
281
|
+
**`metaguide_epub_stream(input_stream: BytesIO, *, remove_metaguiding: bool = False, fixation: int = 3, bold_style: str = "tag", bold_intensity: int = 3) -> BytesIO`**
|
|
225
282
|
|
|
226
283
|
Metaguides an EPUB from a byte stream, useful for in-memory processing or web applications.
|
|
227
284
|
|
|
@@ -243,7 +300,7 @@ with open("output.epub", "wb") as f:
|
|
|
243
300
|
|
|
244
301
|
#### XHTML Functions
|
|
245
302
|
|
|
246
|
-
**`metaguide_xhtml_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False)`**
|
|
303
|
+
**`metaguide_xhtml_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False, fixation: int = 3, bold_style: str = "tag", bold_intensity: int = 3)`**
|
|
247
304
|
|
|
248
305
|
Metaguides an XHTML/HTML file by applying visual anchoring to text content. Supports `.xhtml`, `.html`, and `.htm` files.
|
|
249
306
|
|
|
@@ -257,7 +314,7 @@ metaguide_xhtml_file("article.html", "article_metaguided.html")
|
|
|
257
314
|
metaguide_xhtml_file("article_metaguided.html", "article_restored.html", remove_metaguiding=True)
|
|
258
315
|
```
|
|
259
316
|
|
|
260
|
-
**`metaguide_xhtml_stream(input_file_stream: BytesIO, *, remove_metaguiding: bool = False) -> BytesIO`**
|
|
317
|
+
**`metaguide_xhtml_stream(input_file_stream: BytesIO, *, remove_metaguiding: bool = False, fixation: int = 3, bold_style: str = "tag", bold_intensity: int = 3) -> BytesIO`**
|
|
261
318
|
|
|
262
319
|
Metaguides an XHTML/HTML file from a byte stream.
|
|
263
320
|
|
|
@@ -282,7 +339,7 @@ metaguided_content = output_stream.read().decode("utf-8")
|
|
|
282
339
|
|
|
283
340
|
#### Directory Functions
|
|
284
341
|
|
|
285
|
-
**`metaguide_dir(input_dir: str, output_dir: str, *, remove_metaguiding: bool = False)`**
|
|
342
|
+
**`metaguide_dir(input_dir: str, output_dir: str, *, remove_metaguiding: bool = False, fixation: int = 3, bold_style: str = "tag", bold_intensity: int = 3)`**
|
|
286
343
|
|
|
287
344
|
Metaguides all EPUB and XHTML/HTML files found in a directory recursively.
|
|
288
345
|
|
|
@@ -117,6 +117,54 @@ To metaguide all files in a directory, use the `metaguide-dir` command. The comm
|
|
|
117
117
|
> intellireading metaguide-dir --input_dir mydir --output_dir mydir_metaguided
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
+
#### Control the fixation level
|
|
121
|
+
The `--fixation` option controls how much of each word is bolded. It accepts values from `1` (least bold) to `5` (most bold) and defaults to `3`, which is the historical behaviour of IntelliReading.
|
|
122
|
+
|
|
123
|
+
The option is available on `metaguide-epub`, `metaguide-xhtml`, and `metaguide-dir`:
|
|
124
|
+
|
|
125
|
+
```console
|
|
126
|
+
> intellireading metaguide-epub --input_file mybook.epub --output_file mybook_metaguided.epub --fixation 5
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The public contract is the range `1`–`5`, the default `3`, and the fact that higher levels never bold less of each word (and usually bold more). The exact split point for each word is an implementation detail and may change.
|
|
130
|
+
|
|
131
|
+
The fixation level only applies to new conversions. EPUB files that are already metaguided are copied unchanged. To apply a different level to an already metaguided EPUB, use `--remove_metaguiding` first and then metaguide the result again. Standalone XHTML files have no metaguided marker, so avoid running metaguiding twice on the same XHTML file.
|
|
132
|
+
|
|
133
|
+
#### Control the bold style
|
|
134
|
+
The `--bold_style` option controls how the bold part of each word is rendered. It accepts:
|
|
135
|
+
|
|
136
|
+
- `tag` (default) — uses `<b>` and the font's real bold face;
|
|
137
|
+
- `shadow` — uses `<b class="ir-bold">` plus a CSS `text-shadow`, which keeps the original font metrics;
|
|
138
|
+
- `stroke` — uses `<b class="ir-bold">` plus a CSS `-webkit-text-stroke`, which also keeps the original font metrics.
|
|
139
|
+
|
|
140
|
+
The visual modes (`shadow` and `stroke`) are intended for Kobo kepubs and other WebKit-based readers. They avoid the page count changes that real bold can cause on Kobo, because the text keeps the same width and line breaks. On readers that do not support those CSS properties, the text may render without emphasis; use `tag` for maximum compatibility.
|
|
141
|
+
|
|
142
|
+
The option is available on `metaguide-epub`, `metaguide-xhtml`, and `metaguide-dir`:
|
|
143
|
+
|
|
144
|
+
```console
|
|
145
|
+
> intellireading metaguide-epub --input_file mybook.epub --output_file mybook_metaguided.epub --bold_style shadow
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### Control the bold intensity
|
|
149
|
+
The `--bold_intensity` option controls how strong the visual bold effect is when `--bold_style` is `shadow` or `stroke`. It accepts values from `1` (subtle) to `5` (strongest) and defaults to `3`.
|
|
150
|
+
|
|
151
|
+
```console
|
|
152
|
+
> intellireading metaguide-epub --input_file mybook.epub --output_file mybook_metaguided.epub --bold_style shadow --bold_intensity 5
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
The intensity only affects the visual modes. With `--bold_style tag` the option is ignored, because the real bold face is used.
|
|
156
|
+
|
|
157
|
+
#### What gets metaguided
|
|
158
|
+
Metaguiding only changes prose text inside the document body. The following content is preserved byte-for-byte:
|
|
159
|
+
|
|
160
|
+
- `<style>` and `<script>` elements (CSS and JavaScript)
|
|
161
|
+
- `<pre>` and `<code>` elements (preformatted text and code samples)
|
|
162
|
+
- `<text>` and `<tspan>` elements in SVG
|
|
163
|
+
- CDATA sections
|
|
164
|
+
- HTML comments
|
|
165
|
+
|
|
166
|
+
This keeps stylesheets, scripts and embedded SVG content valid. Elements that are not listed above (for example MathML text elements or `<textarea>`) are still metaguided, so bold tags may be inserted into them. Removal of metaguiding keeps its previous behaviour and can still clean up bold tags added to these regions by older versions.
|
|
167
|
+
|
|
120
168
|
## Experimental Features
|
|
121
169
|
Some features are still experimental and may not work as expected. Use them with caution.
|
|
122
170
|
|
|
@@ -171,7 +219,7 @@ metaguide_xhtml_file("input.html", "output.html")
|
|
|
171
219
|
|
|
172
220
|
#### EPUB Functions
|
|
173
221
|
|
|
174
|
-
**`metaguide_epub_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False)`**
|
|
222
|
+
**`metaguide_epub_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False, fixation: int = 3, bold_style: str = "tag", bold_intensity: int = 3)`**
|
|
175
223
|
|
|
176
224
|
Metaguides an EPUB file by applying visual anchoring to text content within all XHTML files in the EPUB.
|
|
177
225
|
|
|
@@ -181,11 +229,20 @@ from intellireading.client import metaguide_epub_file
|
|
|
181
229
|
# Basic metaguiding
|
|
182
230
|
metaguide_epub_file("mybook.epub", "mybook_metaguided.epub")
|
|
183
231
|
|
|
232
|
+
# Bold more of each word (levels go from 1 to 5, default is 3)
|
|
233
|
+
metaguide_epub_file("mybook.epub", "mybook_metaguided.epub", fixation=5)
|
|
234
|
+
|
|
235
|
+
# Use visual bold (keeps the original font metrics and page count on Kobo kepubs)
|
|
236
|
+
metaguide_epub_file("mybook.epub", "mybook_metaguided.epub", bold_style="shadow")
|
|
237
|
+
|
|
238
|
+
# Use a stronger visual bold effect (intensity goes from 1 to 5, default is 3)
|
|
239
|
+
metaguide_epub_file("mybook.epub", "mybook_metaguided.epub", bold_style="shadow", bold_intensity=5)
|
|
240
|
+
|
|
184
241
|
# Remove metaguiding (experimental)
|
|
185
242
|
metaguide_epub_file("mybook_metaguided.epub", "mybook_original.epub", remove_metaguiding=True)
|
|
186
243
|
```
|
|
187
244
|
|
|
188
|
-
**`metaguide_epub_stream(input_stream: BytesIO, *, remove_metaguiding: bool = False) -> BytesIO`**
|
|
245
|
+
**`metaguide_epub_stream(input_stream: BytesIO, *, remove_metaguiding: bool = False, fixation: int = 3, bold_style: str = "tag", bold_intensity: int = 3) -> BytesIO`**
|
|
189
246
|
|
|
190
247
|
Metaguides an EPUB from a byte stream, useful for in-memory processing or web applications.
|
|
191
248
|
|
|
@@ -207,7 +264,7 @@ with open("output.epub", "wb") as f:
|
|
|
207
264
|
|
|
208
265
|
#### XHTML Functions
|
|
209
266
|
|
|
210
|
-
**`metaguide_xhtml_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False)`**
|
|
267
|
+
**`metaguide_xhtml_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False, fixation: int = 3, bold_style: str = "tag", bold_intensity: int = 3)`**
|
|
211
268
|
|
|
212
269
|
Metaguides an XHTML/HTML file by applying visual anchoring to text content. Supports `.xhtml`, `.html`, and `.htm` files.
|
|
213
270
|
|
|
@@ -221,7 +278,7 @@ metaguide_xhtml_file("article.html", "article_metaguided.html")
|
|
|
221
278
|
metaguide_xhtml_file("article_metaguided.html", "article_restored.html", remove_metaguiding=True)
|
|
222
279
|
```
|
|
223
280
|
|
|
224
|
-
**`metaguide_xhtml_stream(input_file_stream: BytesIO, *, remove_metaguiding: bool = False) -> BytesIO`**
|
|
281
|
+
**`metaguide_xhtml_stream(input_file_stream: BytesIO, *, remove_metaguiding: bool = False, fixation: int = 3, bold_style: str = "tag", bold_intensity: int = 3) -> BytesIO`**
|
|
225
282
|
|
|
226
283
|
Metaguides an XHTML/HTML file from a byte stream.
|
|
227
284
|
|
|
@@ -246,7 +303,7 @@ metaguided_content = output_stream.read().decode("utf-8")
|
|
|
246
303
|
|
|
247
304
|
#### Directory Functions
|
|
248
305
|
|
|
249
|
-
**`metaguide_dir(input_dir: str, output_dir: str, *, remove_metaguiding: bool = False)`**
|
|
306
|
+
**`metaguide_dir(input_dir: str, output_dir: str, *, remove_metaguiding: bool = False, fixation: int = 3, bold_style: str = "tag", bold_intensity: int = 3)`**
|
|
250
307
|
|
|
251
308
|
Metaguides all EPUB and XHTML/HTML files found in a directory recursively.
|
|
252
309
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.2.0"
|
|
@@ -2,6 +2,12 @@ from intellireading.client.app import entrypoint
|
|
|
2
2
|
|
|
3
3
|
# flake8: noqa : F401
|
|
4
4
|
from intellireading.client.metaguiding import (
|
|
5
|
+
BOLD_INTENSITIES,
|
|
6
|
+
BOLD_STYLES,
|
|
7
|
+
DEFAULT_BOLD_INTENSITY,
|
|
8
|
+
DEFAULT_BOLD_STYLE,
|
|
9
|
+
DEFAULT_FIXATION,
|
|
10
|
+
FIXATION_LEVELS,
|
|
5
11
|
metaguide_epub_stream,
|
|
6
12
|
metaguide_xhtml_stream,
|
|
7
13
|
metaguide_dir,
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import click
|
|
2
2
|
import logging
|
|
3
3
|
import sys
|
|
4
|
-
from intellireading.client.metaguiding import
|
|
4
|
+
from intellireading.client.metaguiding import (
|
|
5
|
+
BOLD_INTENSITIES,
|
|
6
|
+
BOLD_STYLES,
|
|
7
|
+
DEFAULT_BOLD_INTENSITY,
|
|
8
|
+
DEFAULT_BOLD_STYLE,
|
|
9
|
+
DEFAULT_FIXATION,
|
|
10
|
+
FIXATION_LEVELS,
|
|
11
|
+
metaguide_epub_file,
|
|
12
|
+
metaguide_dir,
|
|
13
|
+
metaguide_xhtml_file,
|
|
14
|
+
)
|
|
5
15
|
from typing import Any, cast
|
|
6
16
|
from collections.abc import Callable
|
|
7
17
|
|
|
@@ -52,6 +62,47 @@ _remove_metaguiding_option = click.option(
|
|
|
52
62
|
help="Remove metaguiding from the files (EXPERIMENTAL)",
|
|
53
63
|
)
|
|
54
64
|
|
|
65
|
+
_no_about_page_option = click.option(
|
|
66
|
+
"--no_about_page",
|
|
67
|
+
is_flag=True,
|
|
68
|
+
show_default=True,
|
|
69
|
+
default=False,
|
|
70
|
+
help="Do not add the IntelliReading about/donation page to the end of EPUB files",
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
_fixation_option = click.option(
|
|
74
|
+
"--fixation",
|
|
75
|
+
type=click.IntRange(min(FIXATION_LEVELS), max(FIXATION_LEVELS)),
|
|
76
|
+
default=DEFAULT_FIXATION,
|
|
77
|
+
show_default=True,
|
|
78
|
+
help="How much of each word is bolded, from 1 (least) to 5 (most)",
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
_bold_style_option = click.option(
|
|
82
|
+
"--bold_style",
|
|
83
|
+
"--bold-style",
|
|
84
|
+
type=click.Choice(BOLD_STYLES, case_sensitive=False),
|
|
85
|
+
default=DEFAULT_BOLD_STYLE,
|
|
86
|
+
show_default=True,
|
|
87
|
+
help=(
|
|
88
|
+
"How to render the bold emphasis. 'tag' uses <b> (real bold); "
|
|
89
|
+
"'shadow' and 'stroke' keep the original font metrics, which avoids "
|
|
90
|
+
"page count changes on Kobo kepubs"
|
|
91
|
+
),
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
_bold_intensity_option = click.option(
|
|
95
|
+
"--bold_intensity",
|
|
96
|
+
"--bold-intensity",
|
|
97
|
+
type=click.IntRange(min(BOLD_INTENSITIES), max(BOLD_INTENSITIES)),
|
|
98
|
+
default=DEFAULT_BOLD_INTENSITY,
|
|
99
|
+
show_default=True,
|
|
100
|
+
help=(
|
|
101
|
+
"How strong the visual bold effect is, from 1 (subtle) to 5 (strongest). "
|
|
102
|
+
"Only applies to the 'shadow' and 'stroke' styles"
|
|
103
|
+
),
|
|
104
|
+
)
|
|
105
|
+
|
|
55
106
|
|
|
56
107
|
def _exit_with_exception(exception: Exception, exit_code: int = 1, fg: str = "red") -> None:
|
|
57
108
|
"""Exit the program with an exception and exit code"""
|
|
@@ -93,7 +144,21 @@ def _get_from_ctx_if_none(
|
|
|
93
144
|
@_input_file_option
|
|
94
145
|
@_output_file_option
|
|
95
146
|
@_remove_metaguiding_option
|
|
96
|
-
|
|
147
|
+
@_no_about_page_option
|
|
148
|
+
@_fixation_option
|
|
149
|
+
@_bold_style_option
|
|
150
|
+
@_bold_intensity_option
|
|
151
|
+
def metaguide_epub_cmd(
|
|
152
|
+
ctx: click.Context,
|
|
153
|
+
input_file: str,
|
|
154
|
+
output_file: str,
|
|
155
|
+
*,
|
|
156
|
+
remove_metaguiding: bool,
|
|
157
|
+
no_about_page: bool,
|
|
158
|
+
fixation: int = DEFAULT_FIXATION,
|
|
159
|
+
bold_style: str = DEFAULT_BOLD_STYLE,
|
|
160
|
+
bold_intensity: int = DEFAULT_BOLD_INTENSITY,
|
|
161
|
+
) -> None:
|
|
97
162
|
"""Applies or removes metaguiding to the provided epub/kepub file"""
|
|
98
163
|
|
|
99
164
|
try:
|
|
@@ -108,7 +173,15 @@ def metaguide_epub_cmd(ctx: click.Context, input_file: str, output_file: str, *,
|
|
|
108
173
|
output_file = _get_from_ctx_if_none(ctx, "output_file", output_file, lambda: click.prompt("The output file"))
|
|
109
174
|
click.echo(f"Output file: {output_file}")
|
|
110
175
|
|
|
111
|
-
metaguide_epub_file(
|
|
176
|
+
metaguide_epub_file(
|
|
177
|
+
input_file,
|
|
178
|
+
output_file,
|
|
179
|
+
remove_metaguiding=remove_metaguiding,
|
|
180
|
+
include_about_page=not no_about_page,
|
|
181
|
+
fixation=fixation,
|
|
182
|
+
bold_style=bold_style,
|
|
183
|
+
bold_intensity=bold_intensity,
|
|
184
|
+
)
|
|
112
185
|
|
|
113
186
|
# store the output file in the context for chaining commands
|
|
114
187
|
ctx.obj["output_file"] = output_file
|
|
@@ -124,7 +197,21 @@ def metaguide_epub_cmd(ctx: click.Context, input_file: str, output_file: str, *,
|
|
|
124
197
|
@_input_dir_option
|
|
125
198
|
@_output_dir_option
|
|
126
199
|
@_remove_metaguiding_option
|
|
127
|
-
|
|
200
|
+
@_no_about_page_option
|
|
201
|
+
@_fixation_option
|
|
202
|
+
@_bold_style_option
|
|
203
|
+
@_bold_intensity_option
|
|
204
|
+
def metaguide_dir_cmd(
|
|
205
|
+
ctx: click.Context,
|
|
206
|
+
input_dir: str,
|
|
207
|
+
output_dir: str,
|
|
208
|
+
*,
|
|
209
|
+
remove_metaguiding: bool,
|
|
210
|
+
no_about_page: bool,
|
|
211
|
+
fixation: int = DEFAULT_FIXATION,
|
|
212
|
+
bold_style: str = DEFAULT_BOLD_STYLE,
|
|
213
|
+
bold_intensity: int = DEFAULT_BOLD_INTENSITY,
|
|
214
|
+
) -> None:
|
|
128
215
|
"""Applies metaguiding to the provided directory, recursively, for all epubs and xhtml files found in the directory
|
|
129
216
|
input_dir: str
|
|
130
217
|
The input directory
|
|
@@ -149,7 +236,15 @@ def metaguide_dir_cmd(ctx: click.Context, input_dir: str, output_dir: str, *, re
|
|
|
149
236
|
if input_dir == output_dir:
|
|
150
237
|
_exit_with_exception(ValueError("Input and output directories cannot be the same. Exiting..."), fg="red")
|
|
151
238
|
|
|
152
|
-
metaguide_dir(
|
|
239
|
+
metaguide_dir(
|
|
240
|
+
input_dir,
|
|
241
|
+
output_dir,
|
|
242
|
+
remove_metaguiding=remove_metaguiding,
|
|
243
|
+
include_about_page=not no_about_page,
|
|
244
|
+
fixation=fixation,
|
|
245
|
+
bold_style=bold_style,
|
|
246
|
+
bold_intensity=bold_intensity,
|
|
247
|
+
)
|
|
153
248
|
except Exception as e:
|
|
154
249
|
_exit_with_exception(e)
|
|
155
250
|
|
|
@@ -162,7 +257,19 @@ def metaguide_dir_cmd(ctx: click.Context, input_dir: str, output_dir: str, *, re
|
|
|
162
257
|
@_input_file_option
|
|
163
258
|
@_output_file_option
|
|
164
259
|
@_remove_metaguiding_option
|
|
165
|
-
|
|
260
|
+
@_fixation_option
|
|
261
|
+
@_bold_style_option
|
|
262
|
+
@_bold_intensity_option
|
|
263
|
+
def metaguide_xhtml_cmd(
|
|
264
|
+
ctx: click.Context,
|
|
265
|
+
input_file: str,
|
|
266
|
+
output_file: str,
|
|
267
|
+
*,
|
|
268
|
+
remove_metaguiding: bool,
|
|
269
|
+
fixation: int = DEFAULT_FIXATION,
|
|
270
|
+
bold_style: str = DEFAULT_BOLD_STYLE,
|
|
271
|
+
bold_intensity: int = DEFAULT_BOLD_INTENSITY,
|
|
272
|
+
) -> None:
|
|
166
273
|
"""Applies or removes metaguiding to the provided xhtml file"""
|
|
167
274
|
|
|
168
275
|
try:
|
|
@@ -177,7 +284,14 @@ def metaguide_xhtml_cmd(ctx: click.Context, input_file: str, output_file: str, *
|
|
|
177
284
|
output_file = _get_from_ctx_if_none(ctx, "output_file", output_file, lambda: click.prompt("The output file"))
|
|
178
285
|
click.echo(f"Output file: {output_file}")
|
|
179
286
|
|
|
180
|
-
metaguide_xhtml_file(
|
|
287
|
+
metaguide_xhtml_file(
|
|
288
|
+
input_file,
|
|
289
|
+
output_file,
|
|
290
|
+
remove_metaguiding=remove_metaguiding,
|
|
291
|
+
fixation=fixation,
|
|
292
|
+
bold_style=bold_style,
|
|
293
|
+
bold_intensity=bold_intensity,
|
|
294
|
+
)
|
|
181
295
|
|
|
182
296
|
# store the output file in the context for chaining commands
|
|
183
297
|
ctx.obj["output_file"] = output_file
|