Skip to content

Commit 10b8e4b

Browse files
fix: corrige XPath para inline-graphic e validação de containers (#1049)
- Ajusta XPath para usar caminho relativo ao parent em vez de tag genérica - Corrige XPath de containers para verificar ausência de graphic em qualquer nível - Substitui list comprehension por loop explícito com getchildren() para melhor compatibilidade
1 parent 1508c58 commit 10b8e4b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

packtools/sps/utils/xml_fixer.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _remove_and_get_info(xmltree, inline_graphic):
2828
try:
2929
xpath = xmltree.getroottree().getpath(inline_graphic)
3030
except (AttributeError, ValueError):
31-
xpath = f".//{inline_graphic.tag}"
31+
xpath = f"./{old_parent.tag}/inline-graphic"
3232

3333
# Remove inline-graphic from current position
3434
old_parent.remove(inline_graphic)
@@ -65,7 +65,7 @@ def fix_inline_graphic_in_caption(xmltree):
6565
# - Do NOT have a direct child graphic element
6666
xpath_containers = """
6767
(//fig | //table-wrap | //disp-formula)
68-
[(label//inline-graphic or caption//inline-graphic) and not(graphic)]
68+
[(label//inline-graphic or caption//inline-graphic) and not(.//graphic)]
6969
"""
7070

7171
containers = xmltree.xpath(xpath_containers)
@@ -82,10 +82,11 @@ def fix_inline_graphic_in_caption(xmltree):
8282

8383
# Check if the container has only label and/or caption as children
8484
# If there are other elements (table, mathml:math, etc.), do not process
85-
has_only_label_caption = all(
86-
child.tag in ("label", "caption")
87-
for child in container
88-
)
85+
has_only_label_caption = True
86+
for child in container.getchildren():
87+
if child.tag not in ("label", "caption"):
88+
has_only_label_caption = False
89+
break
8990

9091
if not has_only_label_caption:
9192
logger.debug(

0 commit comments

Comments
 (0)