forked from standardebooks/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add build-loi command for updating an LoI file from <figure>s
Text from the <figcaption>, if any, is preferred over that from the <img>'s alt attribute, though this can be controlled on a per-ID basis. If the resulting text is empty, default_link_text is used.
- Loading branch information
Showing
20 changed files
with
630 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" | ||
This module implements the `se build-loi` command. | ||
""" | ||
|
||
import argparse | ||
|
||
import se | ||
from se.se_epub import SeEpub | ||
|
||
|
||
def build_loi(plain_output: bool) -> int: | ||
""" | ||
Entry point for `se build-loi` | ||
""" | ||
|
||
parser = argparse.ArgumentParser(description="Update the LoI file based on all <figure> elements that contain an <img>.") | ||
parser.add_argument("-a", "--prefer-alt-text", dest="prefer_alt_text", nargs="+", help="prefer alt text over <figcaption> for these <figure> IDs") | ||
parser.add_argument("-d", "--default-link-text", dest="default_link_text", metavar="DEFAULT-LINK-TEXT", type=str, default="TODO", help="link text to use if <figcaption> or alt text is absent or empty") | ||
parser.add_argument("directory", metavar="DIRECTORY", help="a Standard Ebooks source directory") | ||
args = parser.parse_args() | ||
|
||
return_code = 0 | ||
|
||
try: | ||
se_epub = SeEpub(args.directory) | ||
prefer_alt_text = set(args.prefer_alt_text or []) | ||
se_epub.generate_loi(prefer_alt_text=prefer_alt_text, default_link_text=args.default_link_text) | ||
|
||
except se.SeException as ex: | ||
se.print_error(ex, plain_output=plain_output) | ||
return_code = ex.code | ||
|
||
return return_code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build-loi -a 'f-8' -d 'placeholder text' |
Oops, something went wrong.