@@ -364,7 +364,7 @@ protected static function parseCell($node, $element, &$styles)
364
364
$ cell = $ element ->addCell (null , $ cellStyles );
365
365
366
366
if (self ::shouldAddTextRun ($ node )) {
367
- return $ cell ->addTextRun (self ::parseInlineStyle ($ node , $ styles ['paragraph ' ]));
367
+ return $ cell ->addTextRun (self ::filterOutNonInheritedStyles ( self :: parseInlineStyle ($ node , $ styles ['paragraph ' ]) ));
368
368
}
369
369
370
370
return $ cell ;
@@ -395,15 +395,51 @@ protected static function shouldAddTextRun(\DOMNode $node)
395
395
*/
396
396
protected static function recursiveParseStylesInHierarchy (\DOMNode $ node , array $ style )
397
397
{
398
- $ parentStyle = self ::parseInlineStyle ($ node , array ());
399
- $ style = array_merge ($ parentStyle , $ style );
398
+ $ parentStyle = array ();
400
399
if ($ node ->parentNode != null && XML_ELEMENT_NODE == $ node ->parentNode ->nodeType ) {
401
- $ style = self ::recursiveParseStylesInHierarchy ($ node ->parentNode , $ style );
400
+ $ parentStyle = self ::recursiveParseStylesInHierarchy ($ node ->parentNode , array () );
402
401
}
402
+ if ($ node ->nodeName === '#text ' ) {
403
+ $ parentStyle = array_merge ($ parentStyle , $ style );
404
+ } else {
405
+ $ parentStyle = self ::filterOutNonInheritedStyles ($ parentStyle );
406
+ }
407
+ $ style = self ::parseInlineStyle ($ node , $ parentStyle );
403
408
404
409
return $ style ;
405
410
}
406
411
412
+ /**
413
+ * Removes non-inherited styles from array
414
+ *
415
+ * @param array &$styles
416
+ */
417
+ protected static function filterOutNonInheritedStyles (array $ styles )
418
+ {
419
+ $ nonInheritedStyles = array (
420
+ 'borderSize ' ,
421
+ 'borderTopSize ' ,
422
+ 'borderRightSize ' ,
423
+ 'borderBottomSize ' ,
424
+ 'borderLeftSize ' ,
425
+ 'borderColor ' ,
426
+ 'borderTopColor ' ,
427
+ 'borderRightColor ' ,
428
+ 'borderBottomColor ' ,
429
+ 'borderLeftColor ' ,
430
+ 'borderStyle ' ,
431
+ 'spaceAfter ' ,
432
+ 'spaceBefore ' ,
433
+ 'underline ' ,
434
+ 'strikethrough ' ,
435
+ 'hidden ' ,
436
+ );
437
+
438
+ $ styles = array_diff_key ($ styles , array_flip ($ nonInheritedStyles ));
439
+
440
+ return $ styles ;
441
+ }
442
+
407
443
/**
408
444
* Parse list node
409
445
*
0 commit comments