Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/p/mobi.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ To update, modify plugins/mobi/__init__.py file, then run ./scripts/gen
| css | | str | Path to css file |
| cover_path | | str | Path to cover file |
| kindlegen_path | | str | Path to kindlegen executable |
| kindlegen_args | `None` | list | Additional arguments forwarded to kindlegen |
| file_size_approx | `271360` | int | Approximate size of each xhtml file (example: 200kb) |
| hide_word_index | `False` | bool | Hide headword in tap-to-check interface |
| spellcheck | `True` | bool | Enable wildcard search and spell correction during word lookup |
Expand Down
6 changes: 6 additions & 0 deletions plugins-meta/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,11 @@
"customValue": true,
"comment": "Path to kindlegen executable"
},
"kindlegen_args": {
"class": "ListOption",
"type": "list",
"comment": "Additional arguments forwarded to kindlegen"
},
"compress": {
"class": "BoolOption",
"type": "bool",
Expand Down Expand Up @@ -913,6 +918,7 @@
"css": "",
"cover_path": "",
"kindlegen_path": "",
"kindlegen_args": null,
"file_size_approx": 271360,
"hide_word_index": false,
"spellcheck": true,
Expand Down
4 changes: 4 additions & 0 deletions pyglossary/plugins/ebook_mobi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
BoolOption,
FileSizeOption,
IntOption,
ListOption,
StrOption,
)

Expand Down Expand Up @@ -58,6 +59,9 @@
"kindlegen_path": StrOption(
comment="Path to kindlegen executable",
),
"kindlegen_args": ListOption(
comment="Additional arguments forwarded to kindlegen",
),
"compress": BoolOption(
disabled=True,
comment="Enable compression",
Expand Down
15 changes: 10 additions & 5 deletions pyglossary/plugins/ebook_mobi/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Writer(EbookWriter):
_compress: bool = False
_keep: bool = False
_kindlegen_path: str = ""
_kindlegen_args: list | None = None
_file_size_approx: int = 271360
_hide_word_index: bool = False
_spellcheck: bool = True
Expand Down Expand Up @@ -296,15 +297,19 @@ def write(self) -> Generator[None, EntryType, None]:
# name = self._glos.getInfo("name")
log.info(f"Creating .mobi file with kindlegen, using {kindlegen_path!r}")
direc, filename = split(filename)

kindlegen_args = self._kindlegen_args or []
kindlegen_args.extend(["-gen_ff_mobi7", "-dont_append_source"])
if isDebug():
kindlegen_args.append("-verbose")
kindlegen_args.extend(["-o", "content.mobi"])
log.info(f"Effective kindlegen arguments: {' '.join(kindlegen_args)}")

cmd = [
kindlegen_path,
join(filename, "OEBPS", "content.opf"),
"-gen_ff_mobi7",
"-dont_append_source",
*kindlegen_args,
]
if isDebug():
cmd.append("-verbose")
cmd += ["-o", "content.mobi"]
proc = subprocess.Popen(
cmd,
cwd=direc,
Expand Down
Loading