Skip to content

Commit bded91a

Browse files
authored
Footnote in listitem (#1289)
* Allow footnote to be added in ListItems
1 parent 04d0c02 commit bded91a

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ v0.15.0 (?? ??? 2018)
2020
- Save PNG alpha information when using remote images. @samsullivan #779
2121
- Fix parsing of `<w:br/>` tag. @troosan #1274
2222
- Bookmark are not writton as internal link in html writer @troosan #1263
23+
- It should be possible to add a Footnote in a ListItemRun @troosan #1287 #1287
2324

2425

2526

samples/Sample_14_ListItem.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
$listItemRun = $section->addListItemRun();
6868
$listItemRun->addText('List item 2');
6969
$listItemRun->addText(' in italic', array('italic' => true));
70+
$footnote = $listItemRun->addFootnote();
71+
$footnote->addText('this is a footnote on a list item');
7072
$listItemRun = $section->addListItemRun();
7173
$listItemRun->addText('List item 3');
7274
$listItemRun->addText(' underlined', array('underline' => 'dash'));

src/PhpWord/Element/AbstractContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private function checkValidity($method)
207207
'Table' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
208208
'CheckBox' => array('Section', 'Header', 'Footer', 'Cell', 'TextRun'),
209209
'TextBox' => array('Section', 'Header', 'Footer', 'Cell'),
210-
'Footnote' => array('Section', 'TextRun', 'Cell'),
210+
'Footnote' => array('Section', 'TextRun', 'Cell', 'ListItemRun'),
211211
'Endnote' => array('Section', 'TextRun', 'Cell'),
212212
'PreserveText' => array('Section', 'Header', 'Footer', 'Cell'),
213213
'Title' => array('Section', 'Cell'),

src/PhpWord/Shared/Html.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ private static function parseList($node, $element, &$styles, &$data)
415415
}
416416
}
417417

418+
/**
419+
* @param bool $isOrderedList
420+
* @return array
421+
*/
418422
private static function getListStyle($isOrderedList)
419423
{
420424
if ($isOrderedList) {
@@ -547,13 +551,13 @@ private static function parseStyle($attribute, $styles)
547551
case 'width':
548552
if (preg_match('/([0-9]+[a-z]+)/', $cValue, $matches)) {
549553
$styles['width'] = Converter::cssToTwip($matches[1]);
550-
$styles['unit'] = \PhpOffice\PhpWord\Style\Table::WIDTH_TWIP;
554+
$styles['unit'] = \PhpOffice\PhpWord\SimpleType\TblWidth::TWIP;
551555
} elseif (preg_match('/([0-9]+)%/', $cValue, $matches)) {
552556
$styles['width'] = $matches[1] * 50;
553-
$styles['unit'] = \PhpOffice\PhpWord\Style\Table::WIDTH_PERCENT;
557+
$styles['unit'] = \PhpOffice\PhpWord\SimpleType\TblWidth::PERCENT;
554558
} elseif (preg_match('/([0-9]+)/', $cValue, $matches)) {
555559
$styles['width'] = $matches[1];
556-
$styles['unit'] = \PhpOffice\PhpWord\Style\Table::WIDTH_AUTO;
560+
$styles['unit'] = \PhpOffice\PhpWord\SimpleType\TblWidth::AUTO;
557561
}
558562
break;
559563
case 'border':

src/PhpWord/Style/Cell.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
namespace PhpOffice\PhpWord\Style;
1919

20+
use PhpOffice\PhpWord\SimpleType\TblWidth;
21+
2022
/**
2123
* Table cell style
2224
*/
@@ -123,7 +125,7 @@ class Cell extends Border
123125
*
124126
* @var string
125127
*/
126-
private $unit = Table::WIDTH_TWIP;
128+
private $unit = TblWidth::TWIP;
127129

128130
/**
129131
* Get vertical align.
@@ -308,7 +310,7 @@ public function getUnit()
308310
*/
309311
public function setUnit($value)
310312
{
311-
$this->unit = $this->setEnumVal($value, array(Table::WIDTH_AUTO, Table::WIDTH_PERCENT, Table::WIDTH_TWIP), Table::WIDTH_TWIP);
313+
$this->unit = $this->setEnumVal($value, array(TblWidth::AUTO, TblWidth::PERCENT, TblWidth::TWIP), TblWidth::TWIP);
312314

313315
return $this;
314316
}

0 commit comments

Comments
 (0)