Skip to content

Commit 87a355b

Browse files
author
Nilton
committed
Bring back b, i, <span style="font-style: italic;"> and <span style="font-weight: bold;">
1 parent 7c256b5 commit 87a355b

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/PhpWord/Shared/Html.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,12 @@ protected static function parseNode($node, $element, $styles = array(), $data =
119119
'h6' => array('Heading', null, $element, $styles, null, 'Heading6', null),
120120
'#text' => array('Text', $node, $element, $styles, null, null, null),
121121
'strong' => array('Property', null, null, $styles, null, 'bold', true),
122+
'b' => array('Property', null, null, $styles, null, 'bold', true),
122123
'em' => array('Property', null, null, $styles, null, 'italic', true),
124+
'i' => array('Property', null, null, $styles, null, 'italic', true),
123125
'sup' => array('Property', null, null, $styles, null, 'superScript', true),
124126
'sub' => array('Property', null, null, $styles, null, 'subScript', true),
127+
'span' => array('Property', null, null, $styles, null, 'span', $node),
125128
'table' => array('Table', $node, $element, $styles, null, 'addTable', true),
126129
'tr' => array('Table', $node, $element, $styles, null, 'addRow', true),
127130
'td' => array('Table', $node, $element, $styles, null, 'addCell', true),
@@ -251,7 +254,16 @@ private static function parseText($node, $element, &$styles)
251254
*/
252255
private static function parseProperty(&$styles, $argument1, $argument2)
253256
{
254-
$styles['font'][$argument1] = $argument2;
257+
if ($argument1 !== 'span') {
258+
$styles['font'][$argument1] = $argument2;
259+
} else {
260+
if (!is_null($argument2->attributes)) {
261+
$nodeAttr = $argument2->attributes->getNamedItem('style');
262+
if (!is_null($nodeAttr) && property_exists($nodeAttr, 'value')) {
263+
$styles['font'] = self::parseStyle($nodeAttr, $styles['font']);
264+
}
265+
}
266+
}
255267

256268
return null;
257269
}
@@ -369,6 +381,20 @@ private static function parseStyle($attribute, $styles)
369381
case 'background-color':
370382
$styles['bgColor'] = trim($cValue, "#");
371383
break;
384+
case 'font-weight':
385+
$tValue = false;
386+
if (preg_match('#bold#', $cValue)) {
387+
$tValue = true; // also match bolder
388+
}
389+
$styles['bold'] = $tValue;
390+
break;
391+
case 'font-style':
392+
$tValue = false;
393+
if (preg_match('#(?:italic|oblique)#', $cValue)) {
394+
$tValue = true;
395+
}
396+
$styles['italic'] = $tValue;
397+
break;
372398
}
373399
}
374400

0 commit comments

Comments
 (0)