Skip to content

Commit

Permalink
Footnote in listitem (#1289)
Browse files Browse the repository at this point in the history
* Allow footnote to be added in ListItems
  • Loading branch information
troosan authored Feb 17, 2018
1 parent 04d0c02 commit bded91a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ v0.15.0 (?? ??? 2018)
- Save PNG alpha information when using remote images. @samsullivan #779
- Fix parsing of `<w:br/>` tag. @troosan #1274
- Bookmark are not writton as internal link in html writer @troosan #1263
- It should be possible to add a Footnote in a ListItemRun @troosan #1287 #1287



Expand Down
2 changes: 2 additions & 0 deletions samples/Sample_14_ListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
$listItemRun = $section->addListItemRun();
$listItemRun->addText('List item 2');
$listItemRun->addText(' in italic', array('italic' => true));
$footnote = $listItemRun->addFootnote();
$footnote->addText('this is a footnote on a list item');
$listItemRun = $section->addListItemRun();
$listItemRun->addText('List item 3');
$listItemRun->addText(' underlined', array('underline' => 'dash'));
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Element/AbstractContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private function checkValidity($method)
'Table' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
'CheckBox' => array('Section', 'Header', 'Footer', 'Cell', 'TextRun'),
'TextBox' => array('Section', 'Header', 'Footer', 'Cell'),
'Footnote' => array('Section', 'TextRun', 'Cell'),
'Footnote' => array('Section', 'TextRun', 'Cell', 'ListItemRun'),
'Endnote' => array('Section', 'TextRun', 'Cell'),
'PreserveText' => array('Section', 'Header', 'Footer', 'Cell'),
'Title' => array('Section', 'Cell'),
Expand Down
10 changes: 7 additions & 3 deletions src/PhpWord/Shared/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,10 @@ private static function parseList($node, $element, &$styles, &$data)
}
}

/**
* @param bool $isOrderedList
* @return array
*/
private static function getListStyle($isOrderedList)
{
if ($isOrderedList) {
Expand Down Expand Up @@ -547,13 +551,13 @@ private static function parseStyle($attribute, $styles)
case 'width':
if (preg_match('/([0-9]+[a-z]+)/', $cValue, $matches)) {
$styles['width'] = Converter::cssToTwip($matches[1]);
$styles['unit'] = \PhpOffice\PhpWord\Style\Table::WIDTH_TWIP;
$styles['unit'] = \PhpOffice\PhpWord\SimpleType\TblWidth::TWIP;
} elseif (preg_match('/([0-9]+)%/', $cValue, $matches)) {
$styles['width'] = $matches[1] * 50;
$styles['unit'] = \PhpOffice\PhpWord\Style\Table::WIDTH_PERCENT;
$styles['unit'] = \PhpOffice\PhpWord\SimpleType\TblWidth::PERCENT;
} elseif (preg_match('/([0-9]+)/', $cValue, $matches)) {
$styles['width'] = $matches[1];
$styles['unit'] = \PhpOffice\PhpWord\Style\Table::WIDTH_AUTO;
$styles['unit'] = \PhpOffice\PhpWord\SimpleType\TblWidth::AUTO;
}
break;
case 'border':
Expand Down
6 changes: 4 additions & 2 deletions src/PhpWord/Style/Cell.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

namespace PhpOffice\PhpWord\Style;

use PhpOffice\PhpWord\SimpleType\TblWidth;

/**
* Table cell style
*/
Expand Down Expand Up @@ -123,7 +125,7 @@ class Cell extends Border
*
* @var string
*/
private $unit = Table::WIDTH_TWIP;
private $unit = TblWidth::TWIP;

/**
* Get vertical align.
Expand Down Expand Up @@ -308,7 +310,7 @@ public function getUnit()
*/
public function setUnit($value)
{
$this->unit = $this->setEnumVal($value, array(Table::WIDTH_AUTO, Table::WIDTH_PERCENT, Table::WIDTH_TWIP), Table::WIDTH_TWIP);
$this->unit = $this->setEnumVal($value, array(TblWidth::AUTO, TblWidth::PERCENT, TblWidth::TWIP), TblWidth::TWIP);

return $this;
}
Expand Down

0 comments on commit bded91a

Please sign in to comment.