New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix TemplateProcessor::fixBrokenMacros to handle whitespaces #1971
base: master
Are you sure you want to change the base?
Conversation
Thank you for the fix! |
Actually I found a case where my fix isn't working: when there is styling tags between the After several tests, I came to the conclusion that the best way to fix those broken macros without breaking anything else was to move all existing tags inside the variable right after it, for example: <w:r><w:t>${</w:t></w:r><w:r><w:t>variable1</w:t></w:r><w:r><w:t>}</w:t></w:r>
<!-- └─────────1──────────┘ └─────────2──────────┘ --> should be transformed to: <w:r><w:t>${variable1}</w:t></w:r><w:r><w:t></w:t></w:r><w:r><w:t></w:t></w:r>
<!-- └─────────1──────────┘└─────────2──────────┘ --> That way we just reassemble all parts of the macro together. But we also need to add <w:r><w:t>${variable1</w:t></w:r><w:r><w:t>} ${variable2</w:t></w:r><w:r><w:t>}</w:t></w:r> that would be transformed to: <w:r><w:t>${variable1}</w:t></w:r><w:r><w:t xml:space="preserve"> ${variable2}</w:t></w:r><w:r><w:t xml:space="preserve"></w:t></w:r>
<!-- └──────────────────┘ │ └──────────────────┘ -->
<!-- we need this └─ to preserve this space (this one does not hurt) --> I updated the fix to handle this |
Will there be any movement on this PR in the near future? |
Gently ping @troosan @will2877 until this is merged you can use |
2d9f999
to
e458249
Compare
Update main regexp so that the full macro is matched (only `{{var}` was matched instead of `{{var}}`, which is a problem because we want to move tags after the whole macro)
I rebased the branch to be up to date with @Progi1984 can you take a look ? |
Description
This is a proposal to fix #590 in a cleaner way than a global regex on the whole document, which might change parts of the document that must not change.
Edit: see #1971 (comment)
TemplateProcessor::fixBrokenMacros()
is a method that strip all tags between${
, the name of the variable and}
(let's call them the 3 parts). If there is a<w:t xml:space="preserve">
in those tags it means that there is a trailing space at the end of the content of the tag, because there is not supposed to be any space between the 3 parts, so the whole must be inside of it in order to keep this trailing space.Examples:
I think it's safe to move the opening tag just before the variable, but one thing I'm not sure about because I don't know Open XML very well, is whether it's safe to prepend the variable by
</w:t></w:r><w:r><w:t xml:space="preserve">
. I think it's ok if a<w:t>
is necessarily in a<w:r>
and there cannot be multiple<w:t>
in a<w:r>
(otherwise we could just remove the</w:r><w:r>
part).Expected result of the above examples:
Checklist:
composer run-script check --timeout=0
and no errors were reported=> it's a bug fix