Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/changes/1.x/1.5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -16,4 +17,4 @@

### BC Breaks

### Notes
### Notes
2 changes: 1 addition & 1 deletion src/PhpWord/Writer/RTF/Element/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
67 changes: 67 additions & 0 deletions src/PhpWord/Writer/RTF/Element/ListItemRun
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
*
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpWord\Writer\RTF\Element;

/**
* ListItem element HTML writer.
*
* @since 0.10.0
*/
class ListItemRun extends TextRun
{
/**
* Write list item.
*
* @return string
*/
public function write()
{
$element = $this->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;
}
}