Fix TemplateProcessor::fixBrokenMacros to handle whitespaces #1971
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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