Skip to content

Commit

Permalink
Merge pull request #441 from hakonhagland/fix_script_figcap
Browse files Browse the repository at this point in the history
Update link keywords script: Do not add links for figure captions
  • Loading branch information
lisajulia authored Dec 23, 2024
2 parents e133191 + fd95841 commit a6fc383
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions scripts/python/src/fodt/keyword_linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def __init__(self, keyword_name: str, kw_uri_map: dict[str, str]) -> None:
self.in_a = False
self.in_math = False # We should not insert links inside math tags
self.in_binary_data = False # We should skip binary data
self.in_draw_frame = False # We should not insert links in Figure captions
self.in_draw_recursion = 0 # We can have nested draw:frame tags
self.content = io.StringIO()
# Create a regex pattern with alternation on the keyword names
self.regex = self.compile_regex()
Expand Down Expand Up @@ -105,6 +107,10 @@ def endElement(self, name: str):
self.in_math = False
elif name == "office:binary-data":
self.in_binary_data = False
elif name == "draw:frame":
self.in_draw_recursion -= 1
if self.in_draw_recursion == 0:
self.in_draw_frame = False
if self.start_tag_open:
self.content.write("/>")
self.start_tag_open = False
Expand Down Expand Up @@ -132,6 +138,7 @@ def maybe_write_characters(self) -> None:
and (not self.not_keyword)
and (not self.in_math)
and (not self.in_binary_data)
and (not self.in_draw_frame)
):
if not self.is_example_p[-1]:
if not self.is_table_caption(characters):
Expand Down Expand Up @@ -184,6 +191,11 @@ def startElement(self, name:str, attrs: xml.sax.xmlreader.AttributesImpl):
elif name == "office:binary-data":
# We need to skip the binary data, otherwise the content will be corrupted
self.in_binary_data = True
elif name == "draw:frame":
# We do not want the script to insert links in a Figure caption. These captions
# are usually inside a draw:frame tag.
self.in_draw_frame = True
self.in_draw_recursion += 1
self.start_tag_open = True
self.content.write(XMLHelper.starttag(name, attrs, close_tag=False))

Expand Down

0 comments on commit a6fc383

Please sign in to comment.