fix: add xml:space=preserve to all w:t elements in generated DOCX

PHPWord's TemplateProcessor strips whitespace from <w:t> elements that
lack xml:space="preserve". Post-process the output DOCX to add this
attribute, preventing words from sticking together (e.g. בהולמועדים,
לקוחנחוץ).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-09 21:38:21 +00:00
parent f8022279ad
commit 53844ace9a
2 changed files with 11 additions and 1 deletions
@@ -374,6 +374,16 @@ class DirectAccessReportGenerator
}
$processor->saveAs($outputPath);
// Fix space preservation: PHPWord strips whitespace from <w:t> elements
// that lack xml:space="preserve", causing words to stick together in RTL docs.
$zip = new \ZipArchive();
if ($zip->open($outputPath) === true) {
$xml = $zip->getFromName('word/document.xml');
$xml = preg_replace('/<w:t(?![^>]*xml:space)/', '<w:t xml:space="preserve"', $xml);
$zip->addFromString('word/document.xml', $xml);
$zip->close();
}
}
private function normalizeDate(?string $value): ?string
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "LegalAssistance",
"version": "2.0.7",
"version": "2.0.8",
"acceptableVersions": [">=8.0.0"],
"php": [">=8.1"],
"releaseDate": "2026-04-09",