archesproject / arches-her

6 stars 12 forks source link

Add management command to fix Word letter template style runs #1224

Closed RobOatesHistoricEngland closed 3 months ago

RobOatesHistoricEngland commented 3 months ago

1214

Preserving style runs in the letter templates allows for richly formatted letters to be produced. However, a downside to this approach is that the template's fields, which get replaced by data, cannot have any changes in the styling. Sometimes, even when the styling has been corrected, Word can still produce multiple runs of text.

Due to the fragmentation of the field tag (e.g., <Contact Name>), it can be internally referenced in the DOCX file as <Contact and Name>. This means that when file_template.py is performing the search and replace operation, <Contact Name> is not found, resulting in <Contact Name> remaining literally in the generated correspondence letter.

This helper management command will parse all the .DOCX files in a given directory (default is docx) and join back together any field tags that have been split apart due to styling changes.