Skip to content

Fix Pandoc subdocument XML namespace handling - #658

Open
aka-debug-jie wants to merge 1 commit into
elapouya:masterfrom
aka-debug-jie:fix/issue-620-pandoc-namespaces
Open

Fix Pandoc subdocument XML namespace handling#658
aka-debug-jie wants to merge 1 commit into
elapouya:masterfrom
aka-debug-jie:fix/issue-620-pandoc-namespaces

Conversation

@aka-debug-jie

Copy link
Copy Markdown

Summary

  • serialize each direct subdocument body child so inherited XML namespaces remain in scope
  • preserve the existing sectPr removal behavior
  • add a Pandoc-generated DOCX regression fixture with an embedded image

Validation

  • reproduced the original Namespace prefix a on graphic is not defined failure on the unfixed baseline
  • verified the rendered DOCX opens with python-docx and its word/document.xml parses with lxml
  • verified the merged document retains one inline image and namespace-resolved DrawingML/PictureML elements
  • passed the complete 37-script test suite, related subdocument/header-footer tests, flake8, package builds, and archive audits

Closes #620

@yangfan-yf-yf yangfan-yf-yf left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for two blocking issues:

  1. Subdoc._get_xml() now serializes each direct body child independently. lxml writes every inherited namespace declaration onto every child, including namespaces that are not used by that child or are already available from the destination document. In a CPython 3.12.3 / lxml 6.1.1 benchmark with a 10,000-paragraph dynamic subdocument, the intermediate fragment grew from 340,000 bytes at 1f143fb to 11,800,000 bytes at 62e0075; median render() time across three fresh runs grew from 0.083 s to 2.400 s. The same path affects every subdocument, not only Pandoc input. Please preserve only the missing or conflicting declarations needed by the inserted content and add a scale regression.

  2. tests/pandoc_subdoc.py is not exercised by the current test job. The job invokes python tests/runtests.py from the repository root, but the runner globs [A-Za-z]*.py relative to the current directory, so it runs setup.py rather than the scripts under tests. It also ignores each subprocess.call() return code. Against 1f143fb, the new regression script exits 1 with the reported namespace error, while runtests.py still exits 0. Please discover tests relative to file and propagate child-process failures, or invoke this regression directly from the test job.

The namespace fix itself handles the reported document correctly: the Pandoc 3.9 reproduction fails at the base with the unbound a prefix and succeeds at this head with the image relationship, a/pic elements, nested section properties, and one final body sectPr intact. Custom default namespaces, prefixed attributes, and conflicting prefix mappings also remained resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Subdocument merge with Pandoc-generated DOCX causes XML namespace errors when opening the resulting file

2 participants