Render placeholders located in hyperlink URLs - #650
Conversation
|
Thanks for the PR. I took a local pass through this because rendering relationship targets seems like the right place to fix hyperlink URLs. What I checked locally on
One edge case I found: when callers pass a custom Minimal reproduction from the new fixture: from jinja2 import Environment
env = Environment(variable_start_string="[[", variable_end_string="]]")
# relationship target is [[ foo ]]
# visible document text renders, but word/_rels/document.xml.rels still contains [[ foo ]]For a relationship-only variable using those delimiters, A small way to keep this aligned with the provided environment would be to base the marker check on the active environment, for example using With that handled, this looks like a useful feature and the fixture is a good addition. |
|
For placeholders in URLs, could you include a regression case with mixed % and brace chars? |
CAOShurong
left a comment
There was a problem hiding this comment.
Reviewed the exact head b98ff321d31bdeceff9c4f306374c1b701361afc independently.
- The full direct-script regression suite passed (including the new hyperlink test); the four optional subdocument tests also passed after installing the declared
docxcomposeextra. - The new test verifies both the visible hyperlink text and the serialized external relationship target after saving the DOCX, and
get_undeclared_template_variables()reports the URL variable as resolved. - Additional exact-head checks passed for a URL containing multiple variables, query-string ampersands, and a custom Jinja filter; the rendered relationship target was correct.
flake8reported 0 findings,git diff --checkpassed, and an isolated sdist/wheel build produceddocxtpl-0.20.2.tar.gzanddocxtpl-0.20.2-py3-none-any.whl.
The implementation limits rendering to external hyperlink relationships and preserves the existing custom Jinja environment, while leaving non-hyperlink relationships untouched. This looks focused and correct to me.
OpenAI Codex assisted with the test setup and execution; I reviewed the diff and observed results before approving.
As of today, if you create a hyperlink in your docx template, placeholders such as
{{ foo }}are rendered only in the visible text of the hyperlink but are ignored if placed in the destination URL.With this simple PR, we'll render those templates even in the URL part making it fully customizable.