Fix Writer losing text when Title contains a TextRun instead a string.
This commit is contained in:
parent
4c9e75088a
commit
8c62cea580
|
|
@ -45,7 +45,7 @@ class Title extends AbstractElement
|
|||
$text = $this->escaper->escapeHtml($text);
|
||||
}
|
||||
} elseif ($text instanceof \PhpOffice\PhpWord\Element\AbstractContainer) {
|
||||
$writer = new Container($this->parentWriter, $this->element);
|
||||
$writer = new Container($this->parentWriter, $text);
|
||||
$text = $writer->write();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
namespace PhpOffice\PhpWord\Writer\HTML;
|
||||
|
||||
use PhpOffice\PhpWord\Element\Text as TextElement;
|
||||
use PhpOffice\PhpWord\Element\TextRun;
|
||||
use PhpOffice\PhpWord\Element\TrackChange;
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Writer\HTML;
|
||||
|
|
@ -138,4 +139,22 @@ class ElementTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
return $dom;
|
||||
}
|
||||
|
||||
public function testWriteTitleTextRun()
|
||||
{
|
||||
$expected = 'Title with TextRun';
|
||||
|
||||
$phpWord = new PhpWord();
|
||||
$section = $phpWord->addSection();
|
||||
|
||||
$textRun = new TextRun();
|
||||
$textRun->addText($expected);
|
||||
|
||||
$section->addTitle($textRun);
|
||||
|
||||
$htmlWriter = new HTML($phpWord);
|
||||
$content = $htmlWriter->getContent();
|
||||
|
||||
$this->assertTrue(strpos($content, $expected) !== false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue