Add HTML writer for Bookmarks + tests
This commit is contained in:
parent
874c6d6fb6
commit
377fb99fbc
|
|
@ -15,7 +15,8 @@ v0.15.0 (?? ??? 2018)
|
||||||
- Fix the size unit of when parsing html images - @troosan #1254
|
- Fix the size unit of when parsing html images - @troosan #1254
|
||||||
- Fixed HTML parsing of nested lists - @troosan #1265
|
- Fixed HTML parsing of nested lists - @troosan #1265
|
||||||
- Save PNG alpha information when using remote images. @samsullivan #779
|
- Save PNG alpha information when using remote images. @samsullivan #779
|
||||||
- fix parsing of `<w:br/>` tag. @troosan #1274
|
- Fix parsing of `<w:br/>` tag. @troosan #1274
|
||||||
|
- Bookmark are not writton as internal link in html writer @troosan #1263
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @see https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2017 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Writer\HTML\Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bookmark element HTML writer
|
||||||
|
*
|
||||||
|
* @since 0.15.0
|
||||||
|
*/
|
||||||
|
class Bookmark extends Text
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Write bookmark
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function write()
|
||||||
|
{
|
||||||
|
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Bookmark) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$content = '';
|
||||||
|
$content .= $this->writeOpening();
|
||||||
|
$content .= "<a name=\"{$this->element->getName()}\"/>";
|
||||||
|
$content .= $this->writeClosing();
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -37,12 +37,12 @@ class Link extends Text
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = '';
|
$prefix = $this->element->isInternal() ? '#' : '';
|
||||||
$content .= $this->writeOpening();
|
$content = $this->writeOpening();
|
||||||
if (Settings::isOutputEscapingEnabled()) {
|
if (Settings::isOutputEscapingEnabled()) {
|
||||||
$content .= "<a href=\"{$this->escaper->escapeHtmlAttr($this->element->getSource())}\">{$this->escaper->escapeHtml($this->element->getText())}</a>";
|
$content .= "<a href=\"{$prefix}{$this->escaper->escapeHtmlAttr($this->element->getSource())}\">{$this->escaper->escapeHtml($this->element->getText())}</a>";
|
||||||
} else {
|
} else {
|
||||||
$content .= "<a href=\"{$this->element->getSource()}\">{$this->element->getText()}</a>";
|
$content .= "<a href=\"{$prefix}{$this->element->getSource()}\">{$this->element->getText()}</a>";
|
||||||
}
|
}
|
||||||
$content .= $this->writeClosing();
|
$content .= $this->writeClosing();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class ElementTest extends \PHPUnit\Framework\TestCase
|
||||||
*/
|
*/
|
||||||
public function testUnmatchedElements()
|
public function testUnmatchedElements()
|
||||||
{
|
{
|
||||||
$elements = array('Container', 'Footnote', 'Image', 'Link', 'ListItem', 'Table', 'Title');
|
$elements = array('Container', 'Footnote', 'Image', 'Link', 'ListItem', 'Table', 'Title', 'Bookmark');
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
$objectClass = 'PhpOffice\\PhpWord\\Writer\\HTML\\Element\\' . $element;
|
$objectClass = 'PhpOffice\\PhpWord\\Writer\\HTML\\Element\\' . $element;
|
||||||
$parentWriter = new HTML();
|
$parentWriter = new HTML();
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ class HTMLTest extends \PHPUnit\Framework\TestCase
|
||||||
);
|
);
|
||||||
$phpWord->addParagraphStyle('Paragraph', array('alignment' => Jc::CENTER, 'spaceAfter' => 20, 'spaceBefore' => 20));
|
$phpWord->addParagraphStyle('Paragraph', array('alignment' => Jc::CENTER, 'spaceAfter' => 20, 'spaceBefore' => 20));
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
$section->addBookmark('top');
|
||||||
$section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'), 'Font', 'Paragraph');
|
$section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'), 'Font', 'Paragraph');
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
$section->addText(
|
$section->addText(
|
||||||
|
|
@ -128,6 +129,7 @@ class HTMLTest extends \PHPUnit\Framework\TestCase
|
||||||
$cell->addFootnote();
|
$cell->addFootnote();
|
||||||
$cell->addEndnote();
|
$cell->addEndnote();
|
||||||
$cell = $table->addRow()->addCell();
|
$cell = $table->addRow()->addCell();
|
||||||
|
$section->addLink('top', 'back to top', null, null, true);
|
||||||
|
|
||||||
$writer = new HTML($phpWord);
|
$writer = new HTML($phpWord);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue