diff --git a/docs/changes/1.x/1.5.0.md b/docs/changes/1.x/1.5.0.md index b96865bada..d8528171e5 100644 --- a/docs/changes/1.x/1.5.0.md +++ b/docs/changes/1.x/1.5.0.md @@ -7,6 +7,7 @@ ### Bug fixes - Set writeAttribute return type by [@radarhere](https://github.com/radarhere) fixing [#2204](https://github.com/PHPOffice/PHPWord/issues/2204) in [#2776](https://github.com/PHPOffice/PHPWord/pull/2776) +- Writer RTF: Create element ListItemRun by [@rasamassen](https://github.com/rasamassen) in [#2823](https://github.com/PHPOffice/PHPWord/pull/2823) ### Miscellaneous @@ -16,4 +17,4 @@ ### BC Breaks -### Notes \ No newline at end of file +### Notes diff --git a/src/PhpWord/Writer/RTF/Element/Container.php b/src/PhpWord/Writer/RTF/Element/Container.php index dcac8ec071..8a5ba87da8 100644 --- a/src/PhpWord/Writer/RTF/Element/Container.php +++ b/src/PhpWord/Writer/RTF/Element/Container.php @@ -46,7 +46,7 @@ public function write() return ''; } $containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1); - $withoutP = in_array($containerClass, ['TextRun', 'Footnote', 'Endnote']) ? true : false; + $withoutP = in_array($containerClass, ['TextRun', 'Footnote', 'Endnote', 'ListItemRun', 'Field']) ? true : false; $content = ''; $elements = $container->getElements(); diff --git a/src/PhpWord/Writer/RTF/Element/ListItemRun b/src/PhpWord/Writer/RTF/Element/ListItemRun new file mode 100644 index 0000000000..d8c13eb962 --- /dev/null +++ b/src/PhpWord/Writer/RTF/Element/ListItemRun @@ -0,0 +1,67 @@ +element; + if (!$element instanceof \PhpOffice\PhpWord\Element\ListItemRun) { + return ''; + } + + $writer = new Container($this->parentWriter, $element); + $this->getStyles(); + + $depth = (int) $element->getDepth(); + $style = $element->getStyle(); + + $content = ''; + $content .= $this->writeOpening(); + if ($style instanceof \PhpOffice\PhpWord\Style\ListItem) { + $numStyle = $style->getNumberingStyle(); + $levels = $numStyle->getLevels(); + $content .= '\ilvl' . $element->getDepth(); + $content .= '\ls' . $style->getNumId(); + $content .= '\tx' . $levels[$depth]->getTabPos(); + $hanging = $levels[$depth]->getLeft() + $levels[$depth]->getHanging(); + $left = 0 - $levels[$depth]->getHanging(); + $content .= '\fi' . $left; + $content .= '\li' . $hanging; + $content .= '\lin' . $hanging; + } + $content .= '{'; + $content .= $writer->write(); + $content .= '}'; + $content .= $this->writeClosing(); + + return $content; + } +}