Skip to content

Commit

Permalink
build-loi: Remove links and noterefs from figcaption.
Browse files Browse the repository at this point in the history
  • Loading branch information
gvtulder authored and acabal committed Sep 23, 2024
1 parent bdce342 commit 48a4536
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions se/se_epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,15 @@ def generate_loi(self) -> str:
if not has_block:
entry = deepcopy(figcaption[0])

if isinstance(entry, se.easy_xml.EasyXmlElement):
# Remove endnote references.
for noteref in entry.xpath("a[contains(@epub:type, 'noteref')]"):
noteref.remove()

# For other links, keep only the contents.
for a in entry.xpath("a"):
a.unwrap()

a = se.easy_xml.EasyXmlElement("<a/>")
a.set_attr("href", f"{file_path.name}#{figure_id}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@
<img alt="Alt is preferred over figcaption with block element."/>
<figcaption><h1>Figure 9</h1></figcaption>
</figure>

<figure id="f-10">
<img/>
<figcaption>Endnote references in figcaption are removed.<a href="endnotes.xhtml#note-8" id="noteref-8" epub:type="noteref">8</a></figcaption>
</figure>

<figure id="f-11">
<img/>
<figcaption>Other hyperlinks are converted to text. <a href="chapter-2.xhtml">See Chapter 2.</a></figcaption>
</figure>
</section>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@
<a href="chapter-1.xhtml#f-9">Alt is preferred over figcaption with block element.</a>
</p>
</li>
<li>
<p>
<a href="chapter-1.xhtml#f-10">Endnote references in figcaption are removed.</a>
</p>
</li>
<li>
<p>
<a href="chapter-1.xhtml#f-11">Other hyperlinks are converted to text. See Chapter 2.</a>
</p>
</li>
<li>
<p>
<a href="chapter-2.xhtml#f-0">Unable to auto-generate LoI text for #f-0.</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@
<img alt="Alt is preferred over figcaption with block element."/>
<figcaption><h1>Figure 9</h1></figcaption>
</figure>

<figure id="f-10">
<img/>
<figcaption>Endnote references in figcaption are removed.<a href="endnotes.xhtml#note-8" id="noteref-8" epub:type="noteref">8</a></figcaption>
</figure>

<figure id="f-11">
<img/>
<figcaption>Other hyperlinks are converted to text. <a href="chapter-2.xhtml">See Chapter 2.</a></figcaption>
</figure>
</section>
</body>
</html>

0 comments on commit 48a4536

Please sign in to comment.