From 289f57cef9c7ed8220d5f283f8c9a39372900258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BCrk?= Date: Mon, 17 Jul 2023 15:40:10 +0200 Subject: [PATCH] [BUGFIX] Handle direct and nested title text paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It seems that in newer formats it's possible that the `w:r` for an pStyle can be deeper nested as a sibling of the parent note. Older versions: ``` Überschrift 1 ``` versu newer versions: ``` Überschrift 1 ``` Therefore, this change now uses a double check for the direct and the nested variant to detect the content (text) of a title text section: ```php // old 'w:r', $domNode ); // new 'w:r|w:sdt/w:sdtContent/w:r', $domNode ); ``` in `\PhpOffice\PhpWord\Reader\Word2007\AbstractPart::readParagraph()`. --- src/PhpWord/Reader/Word2007/AbstractPart.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/Reader/Word2007/AbstractPart.php b/src/PhpWord/Reader/Word2007/AbstractPart.php index 95799387ed..28af447aad 100644 --- a/src/PhpWord/Reader/Word2007/AbstractPart.php +++ b/src/PhpWord/Reader/Word2007/AbstractPart.php @@ -255,7 +255,8 @@ protected function readParagraph(XMLReader $xmlReader, DOMElement $domNode, $par $headingDepth = $xmlReader->elementExists('w:pPr', $domNode) ? $this->getHeadingDepth($paragraphStyle) : null; if ($headingDepth !== null) { $textContent = null; - $nodes = $xmlReader->getElements('w:r|w:hyperlink', $domNode); + // @todo Evaluate if a generic relative './/w:r' would be better fitting here. + $nodes = $xmlReader->getElements('w:r|w:sdt/w:sdtContent/w:r|w:hyperlink|w:sdt/w:sdtContent/w:hyperlink', $domNode); if ($nodes->length === 1) { $textContent = htmlspecialchars($xmlReader->getValue('w:t', $nodes->item(0)), ENT_QUOTES, 'UTF-8'); } else {