Skip to content

Commit 18c26f9

Browse files
authored
Merge pull request #1436 from begnini/fixing_title
HTML Title Writer loses text when Title contains a TextRun instead a string.
2 parents f376f20 + 8c62cea commit 18c26f9

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/PhpWord/Writer/HTML/Element/Title.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function write()
4545
$text = $this->escaper->escapeHtml($text);
4646
}
4747
} elseif ($text instanceof \PhpOffice\PhpWord\Element\AbstractContainer) {
48-
$writer = new Container($this->parentWriter, $this->element);
48+
$writer = new Container($this->parentWriter, $text);
4949
$text = $writer->write();
5050
}
5151

tests/PhpWord/Writer/HTML/ElementTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
namespace PhpOffice\PhpWord\Writer\HTML;
1919

2020
use PhpOffice\PhpWord\Element\Text as TextElement;
21+
use PhpOffice\PhpWord\Element\TextRun;
2122
use PhpOffice\PhpWord\Element\TrackChange;
2223
use PhpOffice\PhpWord\PhpWord;
2324
use PhpOffice\PhpWord\Writer\HTML;
@@ -138,4 +139,22 @@ private function getAsHTML(PhpWord $phpWord)
138139

139140
return $dom;
140141
}
142+
143+
public function testWriteTitleTextRun()
144+
{
145+
$expected = 'Title with TextRun';
146+
147+
$phpWord = new PhpWord();
148+
$section = $phpWord->addSection();
149+
150+
$textRun = new TextRun();
151+
$textRun->addText($expected);
152+
153+
$section->addTitle($textRun);
154+
155+
$htmlWriter = new HTML($phpWord);
156+
$content = $htmlWriter->getContent();
157+
158+
$this->assertTrue(strpos($content, $expected) !== false);
159+
}
141160
}

0 commit comments

Comments
 (0)