Skip to content

Commit 379df3c

Browse files
Niltontroosan
authored andcommitted
Bring back b, i, <span style="font-style: italic;"> and <span style="font-weight: bold;">
1 parent e4fe0c6 commit 379df3c

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
@@ -117,9 +117,12 @@ protected static function parseNode($node, $element, $styles = array(), $data =
117117
'h6' => array('Heading', null, $element, $styles, null, 'Heading6', null),
118118
'#text' => array('Text', $node, $element, $styles, null, null, null),
119119
'strong' => array('Property', null, null, $styles, null, 'bold', true),
120+
'b' => array('Property', null, null, $styles, null, 'bold', true),
120121
'em' => array('Property', null, null, $styles, null, 'italic', true),
122+
'i' => array('Property', null, null, $styles, null, 'italic', true),
121123
'sup' => array('Property', null, null, $styles, null, 'superScript', true),
122124
'sub' => array('Property', null, null, $styles, null, 'subScript', true),
125+
'span' => array('Property', null, null, $styles, null, 'span', $node),
123126
'table' => array('Table', $node, $element, $styles, null, 'addTable', true),
124127
'tr' => array('Table', $node, $element, $styles, null, 'addRow', true),
125128
'td' => array('Table', $node, $element, $styles, null, 'addCell', true),
@@ -246,7 +249,16 @@ private static function parseText($node, $element, &$styles)
246249
*/
247250
private static function parseProperty(&$styles, $argument1, $argument2)
248251
{
249-
$styles['font'][$argument1] = $argument2;
252+
if ($argument1 !== 'span') {
253+
$styles['font'][$argument1] = $argument2;
254+
} else {
255+
if (!is_null($argument2->attributes)) {
256+
$nodeAttr = $argument2->attributes->getNamedItem('style');
257+
if (!is_null($nodeAttr) && property_exists($nodeAttr, 'value')) {
258+
$styles['font'] = self::parseStyle($nodeAttr, $styles['font']);
259+
}
260+
}
261+
}
250262

251263
return null;
252264
}
@@ -362,6 +374,20 @@ private static function parseStyle($attribute, $styles)
362374
case 'background-color':
363375
$styles['bgColor'] = trim($cValue, '#');
364376
break;
377+
case 'font-weight':
378+
$tValue = false;
379+
if (preg_match('#bold#', $cValue)) {
380+
$tValue = true; // also match bolder
381+
}
382+
$styles['bold'] = $tValue;
383+
break;
384+
case 'font-style':
385+
$tValue = false;
386+
if (preg_match('#(?:italic|oblique)#', $cValue)) {
387+
$tValue = true;
388+
}
389+
$styles['italic'] = $tValue;
390+
break;
365391
}
366392
}
367393

0 commit comments

Comments
 (0)