fix parsing of link style

This commit is contained in:
troosan 2018-04-25 23:57:07 +02:00
parent 84fa44090f
commit 94be56b0ec
3 changed files with 4 additions and 2 deletions

View File

@ -11,7 +11,7 @@ $html = '<h1>Adding element via HTML</h1>';
$html .= '<p>Some well-formed HTML snippet needs to be used</p>'; $html .= '<p>Some well-formed HTML snippet needs to be used</p>';
$html .= '<p>With for example <strong>some<sup>1</sup> <em>inline</em> formatting</strong><sub>1</sub></p>'; $html .= '<p>With for example <strong>some<sup>1</sup> <em>inline</em> formatting</strong><sub>1</sub></p>';
$html .= '<p>A link to <a href="http://phpword.readthedocs.io/">Read the docs</a></p>'; $html .= '<p>A link to <a href="http://phpword.readthedocs.io/" style="text-decoration: underline">Read the docs</a></p>';
$html .= '<p lang="he-IL" style="text-align: right; direction: rtl">היי, זה פסקה מימין לשמאל</p>'; $html .= '<p lang="he-IL" style="text-align: right; direction: rtl">היי, זה פסקה מימין לשמאל</p>';

View File

@ -721,7 +721,7 @@ class Html
break; break;
} }
} }
self::parseInlineStyle($node, $styles['font']); $styles['font'] = self::parseInlineStyle($node, $styles['font']);
if (strpos($target, '#') === 0) { if (strpos($target, '#') === 0) {
return $element->addLink(substr($target, 1), $node->textContent, $styles['font'], $styles['paragraph'], true); return $element->addLink(substr($target, 1), $node->textContent, $styles['font'], $styles['paragraph'], true);

View File

@ -458,6 +458,8 @@ class HtmlTest extends \PHPUnit\Framework\TestCase
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:hyperlink')); $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:hyperlink'));
$this->assertEquals('link text', $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t')->nodeValue); $this->assertEquals('link text', $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t')->nodeValue);
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:hyperlink/w:r/w:rPr/w:u'));
$this->assertEquals('single', $doc->getElementAttribute('/w:document/w:body/w:p/w:hyperlink/w:r/w:rPr/w:u', 'w:val'));
$phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection(); $section = $phpWord->addSection();