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>
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

1 participant