Footnote in listitem (#1289)

* Allow footnote to be added in ListItems
This commit is contained in:
troosan 2018-02-18 00:39:00 +01:00 committed by GitHub
parent 04d0c02e23
commit bded91af9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 6 deletions

View File

@ -20,6 +20,7 @@ v0.15.0 (?? ??? 2018)
- Save PNG alpha information when using remote images. @samsullivan #779 - Save PNG alpha information when using remote images. @samsullivan #779
- Fix parsing of `<w:br/>` tag. @troosan #1274 - Fix parsing of `<w:br/>` tag. @troosan #1274
- Bookmark are not writton as internal link in html writer @troosan #1263 - 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

View File

@ -67,6 +67,8 @@ $listItemRun->addText(' in bold', array('bold' => true));
$listItemRun = $section->addListItemRun(); $listItemRun = $section->addListItemRun();
$listItemRun->addText('List item 2'); $listItemRun->addText('List item 2');
$listItemRun->addText(' in italic', array('italic' => true)); $listItemRun->addText(' in italic', array('italic' => true));
$footnote = $listItemRun->addFootnote();
$footnote->addText('this is a footnote on a list item');
$listItemRun = $section->addListItemRun(); $listItemRun = $section->addListItemRun();
$listItemRun->addText('List item 3'); $listItemRun->addText('List item 3');
$listItemRun->addText(' underlined', array('underline' => 'dash')); $listItemRun->addText(' underlined', array('underline' => 'dash'));

View File

@ -207,7 +207,7 @@ abstract class AbstractContainer extends AbstractElement
'Table' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'), 'Table' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
'CheckBox' => array('Section', 'Header', 'Footer', 'Cell', 'TextRun'), 'CheckBox' => array('Section', 'Header', 'Footer', 'Cell', 'TextRun'),
'TextBox' => array('Section', 'Header', 'Footer', 'Cell'), 'TextBox' => array('Section', 'Header', 'Footer', 'Cell'),
'Footnote' => array('Section', 'TextRun', 'Cell'), 'Footnote' => array('Section', 'TextRun', 'Cell', 'ListItemRun'),
'Endnote' => array('Section', 'TextRun', 'Cell'), 'Endnote' => array('Section', 'TextRun', 'Cell'),
'PreserveText' => array('Section', 'Header', 'Footer', 'Cell'), 'PreserveText' => array('Section', 'Header', 'Footer', 'Cell'),
'Title' => array('Section', 'Cell'), 'Title' => array('Section', 'Cell'),

View File

@ -415,6 +415,10 @@ class Html
} }
} }
/**
* @param bool $isOrderedList
* @return array
*/
private static function getListStyle($isOrderedList) private static function getListStyle($isOrderedList)
{ {
if ($isOrderedList) { if ($isOrderedList) {
@ -547,13 +551,13 @@ class Html
case 'width': case 'width':
if (preg_match('/([0-9]+[a-z]+)/', $cValue, $matches)) { if (preg_match('/([0-9]+[a-z]+)/', $cValue, $matches)) {
$styles['width'] = Converter::cssToTwip($matches[1]); $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)) { } elseif (preg_match('/([0-9]+)%/', $cValue, $matches)) {
$styles['width'] = $matches[1] * 50; $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)) { } elseif (preg_match('/([0-9]+)/', $cValue, $matches)) {
$styles['width'] = $matches[1]; $styles['width'] = $matches[1];
$styles['unit'] = \PhpOffice\PhpWord\Style\Table::WIDTH_AUTO; $styles['unit'] = \PhpOffice\PhpWord\SimpleType\TblWidth::AUTO;
} }
break; break;
case 'border': case 'border':

View File

@ -17,6 +17,8 @@
namespace PhpOffice\PhpWord\Style; namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\SimpleType\TblWidth;
/** /**
* Table cell style * Table cell style
*/ */
@ -123,7 +125,7 @@ class Cell extends Border
* *
* @var string * @var string
*/ */
private $unit = Table::WIDTH_TWIP; private $unit = TblWidth::TWIP;
/** /**
* Get vertical align. * Get vertical align.
@ -308,7 +310,7 @@ class Cell extends Border
*/ */
public function setUnit($value) 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; return $this;
} }