• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PHPOffice / PHPWord / 13168674058

05 Feb 2025 11:41PM UTC coverage: 96.751% (+0.002%) from 96.749%
13168674058

Pull #2533

github

web-flow
Merge f3f7d9a47 into 1be7a807f
Pull Request #2533: Html Reader Process Titles as Headings Not Paragraphs

16 of 17 new or added lines in 3 files covered. (94.12%)

1 existing line in 1 file now uncovered.

12478 of 12897 relevant lines covered (96.75%)

34.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.44
/src/PhpWord/Writer/HTML/Element/Title.php
1
<?php
2

3
/**
4
 * This file is part of PHPWord - A pure PHP library for reading and writing
5
 * word processing documents.
6
 *
7
 * PHPWord is free software distributed under the terms of the GNU Lesser
8
 * General Public License version 3 as published by the Free Software Foundation.
9
 *
10
 * For the full copyright and license information, please read the LICENSE
11
 * file that was distributed with this source code. For the full list of
12
 * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
13
 *
14
 * @see         https://github.com/PHPOffice/PHPWord
15
 *
16
 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17
 */
18

19
namespace PhpOffice\PhpWord\Writer\HTML\Element;
20

21
use PhpOffice\PhpWord\Element\Title as PhpWordTitle;
22
use PhpOffice\PhpWord\Writer\HTML;
23
use PhpOffice\PhpWord\Writer\HTML\Style\Paragraph;
24

25
/**
26
 * TextRun element HTML writer.
27
 *
28
 * @since 0.10.0
29
 */
30
class Title extends AbstractElement
31
{
32
    /**
33
     * Write heading.
34
     *
35
     * @return string
36
     */
37
    public function write()
38
    {
39
        if (!$this->element instanceof PhpWordTitle) {
5✔
40
            return '';
1✔
41
        }
42

43
        $tag = 'h' . $this->element->getDepth();
4✔
44

45
        $text = $this->element->getText();
4✔
46
        $paragraphStyle = null;
4✔
47
        if (is_string($text)) {
4✔
48
            $text = $this->parentWriter->escapeHTML($text);
3✔
49
        } else {
50
            $paragraphStyle = $text->getParagraphStyle();
2✔
51
            $writer = new Container($this->parentWriter, $text);
2✔
52
            $text = $writer->write();
2✔
53
        }
54
        $css = '';
4✔
55
        if (is_object($paragraphStyle)) {
4✔
56
            $styleWriter = new Paragraph($paragraphStyle);
2✔
57
            $write = $styleWriter->write();
2✔
58
            if ($write !== '') {
2✔
NEW
59
                $css = " style=\"$write\"";
×
60
            }
61
        }
62

63
        $content = "<{$tag}{$css}>{$text}</{$tag}>" . PHP_EOL;
4✔
64

65
        return $content;
4✔
66
    }
67
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc