From 3cedf1ee38b2413e399cf2e5577c20c92c54aded Mon Sep 17 00:00:00 2001 From: Gijs van Tulder Date: Mon, 23 Sep 2024 10:22:14 +0200 Subject: [PATCH] build-loi: Remove links and noterefs from figcaption. --- se/se_epub.py | 8 ++++++++ .../test-1/golden/src/epub/text/chapter-1.xhtml | 10 ++++++++++ .../build-loi/test-1/golden/src/epub/text/loi.xhtml | 10 ++++++++++ .../build-loi/test-1/in/src/epub/text/chapter-1.xhtml | 10 ++++++++++ 4 files changed, 38 insertions(+) diff --git a/se/se_epub.py b/se/se_epub.py index 4390a3cf..6be122c8 100644 --- a/se/se_epub.py +++ b/se/se_epub.py @@ -962,6 +962,14 @@ def generate_loi(self) -> str: if not has_block: entry = deepcopy(figcaption[0]) + # 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.set_attr("href", f"{file_path.name}#{figure_id}") diff --git a/tests/draft_commands/build-loi/test-1/golden/src/epub/text/chapter-1.xhtml b/tests/draft_commands/build-loi/test-1/golden/src/epub/text/chapter-1.xhtml index c8161528..31239fd7 100644 --- a/tests/draft_commands/build-loi/test-1/golden/src/epub/text/chapter-1.xhtml +++ b/tests/draft_commands/build-loi/test-1/golden/src/epub/text/chapter-1.xhtml @@ -51,6 +51,16 @@ Alt is preferred over figcaption with block element.

Figure 9

+ +
+ +
Endnote references in figcaption are removed.8
+
+ +
+ +
Other hyperlinks are converted to text. See Chapter 2.
+
diff --git a/tests/draft_commands/build-loi/test-1/golden/src/epub/text/loi.xhtml b/tests/draft_commands/build-loi/test-1/golden/src/epub/text/loi.xhtml index bfbb59d0..0520f14c 100644 --- a/tests/draft_commands/build-loi/test-1/golden/src/epub/text/loi.xhtml +++ b/tests/draft_commands/build-loi/test-1/golden/src/epub/text/loi.xhtml @@ -50,6 +50,16 @@ Alt is preferred over figcaption with block element.

+
  • +

    + Endnote references in figcaption are removed. +

    +
  • +
  • +

    + Other hyperlinks are converted to text. See Chapter 2. +

    +
  • Unable to auto-generate LoI text for #f-0. diff --git a/tests/draft_commands/build-loi/test-1/in/src/epub/text/chapter-1.xhtml b/tests/draft_commands/build-loi/test-1/in/src/epub/text/chapter-1.xhtml index c8161528..31239fd7 100644 --- a/tests/draft_commands/build-loi/test-1/in/src/epub/text/chapter-1.xhtml +++ b/tests/draft_commands/build-loi/test-1/in/src/epub/text/chapter-1.xhtml @@ -51,6 +51,16 @@ Alt is preferred over figcaption with block element.

    Figure 9

    + +
    + +
    Endnote references in figcaption are removed.8
    +
    + +
    + +
    Other hyperlinks are converted to text. See Chapter 2.
    +