Skip to content

Fix escaped Jinja delimiters split across Word runs - #662

Open
CAOShurong wants to merge 1 commit into
elapouya:masterfrom
CAOShurong:codex/fix-548-escaped-delimiters
Open

Fix escaped Jinja delimiters split across Word runs#662
CAOShurong wants to merge 1 commit into
elapouya:masterfrom
CAOShurong:codex/fix-548-escaped-delimiters

Conversation

@CAOShurong

Copy link
Copy Markdown

Closes #548.

Problem

Jinja's escaped delimiters ({_{, }_}, {_%, %_}) render correctly when all three characters are in one Word run. When Word splits those characters across separate <w:r> elements, the run markup remains between them and the final delimiter replacement never sees a contiguous token.

Fix

  • Join XML-tag-only gaps inside the four exact escaped delimiter tokens before the existing Jinja cleanup.
  • Refuse to cross a paragraph boundary, so unrelated text and structure are not removed.
  • Add a generated DOCX regression covering both single-run and split-run delimiters.
  • Preserve the owner's prior false-positive examples ({a_{hello and {f_{) unchanged.

Verification

  • Reproduced the bug from the exact DOCX attached to Escaping delimiters cannot render properly #548: current master fixed the four single-run examples but left all four split-run examples escaped.
  • With this change, all eight examples render to {%, %}, {{, and }} as intended.
  • The new regression fails on current master and passes on this branch.
  • Python 3.9 and 3.13: 37 non-CLI test scripts passed; the module CLI was also run separately and generated a valid DOCX.
  • flake8 . --count --max-line-length=127 --show-source --statistics: 0 findings.
  • Clean sdist/wheel build and clean wheel installation passed; the installed wheel reproduced the corrected behavior.

OpenAI Codex assisted with reproduction, implementation, and test execution. I reviewed the diff and all reported results before submitting.

Join only the four supported escaped Jinja delimiter tokens when Word has divided their characters into separate runs. Keep matching within one paragraph and add regression coverage for single-run, split-run, and false-positive cases.

Assisted-by: OpenAI Codex <noreply@openai.com>
Signed-off-by: CAOShurong <170531907+CAOShurong@users.noreply.github.com>

@ahmetmusab42-stack ahmetmusab42-stack 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.

Tested exact head a8290b9 independently.

  • Reproduced #548 with the original attached DOCX: master leaves the four split-run escaped delimiters unchanged, while this branch renders all four as {%, %}, {{, and }}.
  • Ran the new regression test successfully on Python 3.12 and 3.13.
  • Exercised all four delimiters across both possible paragraph-boundary splits (8 raw OOXML cases); none were joined across w:p boundaries.
  • Confirmed the two non-delimiter examples remain unchanged.
  • Ran the standalone test scripts, flake8, uv build, and a separate exact-venv CLI render; all relevant checks passed. (The existing module_execute.py runner caveat is unrelated and already tracked by #652.)

The change is focused, fixes the reported document, and I did not find a blocking issue.

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.

Escaping delimiters cannot render properly

2 participants