Skip to content

Commit

Permalink
Make generate_loi self-contained
Browse files Browse the repository at this point in the history
  • Loading branch information
apasel422 committed Jul 1, 2024
1 parent 0a9b3cd commit f5acf20
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 1 addition & 4 deletions se/commands/build_loi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import argparse

import se
import se.easy_xml
from se.se_epub import SeEpub

def build_loi(plain_output: bool) -> int:
Expand All @@ -30,9 +29,7 @@ def build_loi(plain_output: bool) -> int:
return ex.code

try:
loi_dom = se_epub.get_dom(se_epub.loi_path)
se_epub.generate_loi(loi_dom)
xhtml = se.formatting.format_xhtml(loi_dom.to_string())
xhtml = se_epub.generate_loi()

if args.stdout:
print(xhtml)
Expand Down
5 changes: 4 additions & 1 deletion se/se_epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,13 +915,14 @@ def shift_illustrations(self, target_illustration_number: int, step: int = 1) ->
with open(file_path, "w", encoding="utf-8") as file:
file.write(dom.to_string())

def generate_loi(self, loi_dom: se.easy_xml.EasyXmlTree) -> None:
def generate_loi(self) -> str:
"""
Updates the given LoI DOM based on all <figure> elements that contain an
<img>. Text from the <figcaption>, if any, is preferred over that from
the <img>'s alt attribute.
"""

loi_dom = self.get_dom(self.loi_path)
ols = loi_dom.xpath("/html/body/nav/ol")
if len(ols) != 1:
raise se.InvalidSeEbookException(f"LoI contains unexpected number of [html]<ol/>[/]: [path][link=file://{self.loi_path}]{self.loi_path}[/][/].")
Expand Down Expand Up @@ -967,6 +968,8 @@ def generate_loi(self, loi_dom: se.easy_xml.EasyXmlTree) -> None:
li.append(p)
ols[0].append(li)

return se.formatting.format_xhtml(loi_dom.to_string())

def set_release_timestamp(self) -> None:
"""
If this ebook has not yet been released, set the first release timestamp in the metadata file.
Expand Down

0 comments on commit f5acf20

Please sign in to comment.