@@ -401,7 +401,7 @@ protected static function parseCell($node, $element, &$styles)
401
401
$ cell = $ element ->addCell ($ width , $ cellStyles );
402
402
403
403
if (self ::shouldAddTextRun ($ node )) {
404
- return $ cell ->addTextRun (self ::parseInlineStyle ($ node , $ styles ['paragraph ' ]));
404
+ return $ cell ->addTextRun (self ::filterOutNonInheritedStyles ( self :: parseInlineStyle ($ node , $ styles ['paragraph ' ]) ));
405
405
}
406
406
407
407
return $ cell ;
@@ -432,15 +432,51 @@ protected static function shouldAddTextRun(\DOMNode $node)
432
432
*/
433
433
protected static function recursiveParseStylesInHierarchy (\DOMNode $ node , array $ style )
434
434
{
435
- $ parentStyle = self ::parseInlineStyle ($ node , array ());
436
- $ style = array_merge ($ parentStyle , $ style );
435
+ $ parentStyle = array ();
437
436
if ($ node ->parentNode != null && XML_ELEMENT_NODE == $ node ->parentNode ->nodeType ) {
438
- $ style = self ::recursiveParseStylesInHierarchy ($ node ->parentNode , $ style );
437
+ $ parentStyle = self ::recursiveParseStylesInHierarchy ($ node ->parentNode , array () );
439
438
}
439
+ if ($ node ->nodeName === '#text ' ) {
440
+ $ parentStyle = array_merge ($ parentStyle , $ style );
441
+ } else {
442
+ $ parentStyle = self ::filterOutNonInheritedStyles ($ parentStyle );
443
+ }
444
+ $ style = self ::parseInlineStyle ($ node , $ parentStyle );
440
445
441
446
return $ style ;
442
447
}
443
448
449
+ /**
450
+ * Removes non-inherited styles from array
451
+ *
452
+ * @param array &$styles
453
+ */
454
+ protected static function filterOutNonInheritedStyles (array $ styles )
455
+ {
456
+ $ nonInheritedStyles = array (
457
+ 'borderSize ' ,
458
+ 'borderTopSize ' ,
459
+ 'borderRightSize ' ,
460
+ 'borderBottomSize ' ,
461
+ 'borderLeftSize ' ,
462
+ 'borderColor ' ,
463
+ 'borderTopColor ' ,
464
+ 'borderRightColor ' ,
465
+ 'borderBottomColor ' ,
466
+ 'borderLeftColor ' ,
467
+ 'borderStyle ' ,
468
+ 'spaceAfter ' ,
469
+ 'spaceBefore ' ,
470
+ 'underline ' ,
471
+ 'strikethrough ' ,
472
+ 'hidden ' ,
473
+ );
474
+
475
+ $ styles = array_diff_key ($ styles , array_flip ($ nonInheritedStyles ));
476
+
477
+ return $ styles ;
478
+ }
479
+
444
480
/**
445
481
* Parse list node
446
482
*
0 commit comments