Skip to content

Commit fa52c92

Browse files
authored
Merge pull request #2041 from joelgo/patch-1
Update Html parser to accept line-height:normal
2 parents 3a7301c + a4055fb commit fa52c92

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/PhpWord/Shared/Html.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,10 @@ protected static function parseStyle($attribute, $styles)
661661
break;
662662
case 'line-height':
663663
$matches = array();
664-
if (preg_match('/([0-9]+\.?[0-9]*[a-z]+)/', $cValue, $matches)) {
664+
if ($cValue === 'normal') {
665+
$spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::AUTO;
666+
$spacing = 0;
667+
} elseif (preg_match('/([0-9]+\.?[0-9]*[a-z]+)/', $cValue, $matches)) {
665668
//matches number with a unit, e.g. 12px, 15pt, 20mm, ...
666669
$spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::EXACT;
667670
$spacing = Converter::cssToTwip($matches[1]);

tests/PhpWord/Shared/HtmlTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ public function testParseLineHeight()
158158
Html::addHtml($section, '<p style="line-height: 15pt;">test</p>');
159159
Html::addHtml($section, '<p style="line-height: 120%;">test</p>');
160160
Html::addHtml($section, '<p style="line-height: 0.17in;">test</p>');
161+
Html::addHtml($section, '<p style="line-height: normal;">test</p>');
161162

162163
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
163164
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[1]/w:pPr/w:spacing'));
@@ -175,6 +176,10 @@ public function testParseLineHeight()
175176
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[4]/w:pPr/w:spacing'));
176177
$this->assertEquals(244.8, $doc->getElementAttribute('/w:document/w:body/w:p[4]/w:pPr/w:spacing', 'w:line'));
177178
$this->assertEquals(LineSpacingRule::EXACT, $doc->getElementAttribute('/w:document/w:body/w:p[4]/w:pPr/w:spacing', 'w:lineRule'));
179+
180+
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[5]/w:pPr/w:spacing'));
181+
$this->assertEquals(Paragraph::LINE_HEIGHT, $doc->getElementAttribute('/w:document/w:body/w:p[5]/w:pPr/w:spacing', 'w:line'));
182+
$this->assertEquals(LineSpacingRule::AUTO, $doc->getElementAttribute('/w:document/w:body/w:p[5]/w:pPr/w:spacing', 'w:lineRule'));
178183
}
179184

180185
/**

0 commit comments

Comments
 (0)