Skip to content

Commit 9d557ca

Browse files
committed
Streamlined code in tag::html().
Added phpunit.xml. Bumped version to 1.1.0.
1 parent 73565f2 commit 9d557ca

File tree

5 files changed

+32
-17
lines changed

5 files changed

+32
-17
lines changed

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
/workspace
2-
/node_modules
3-
/tools
4-
52
/vendor/
63
/coverage
7-
/phpunit.xml
84
/tests/cache

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "HTMLdoc",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "A token based HTML Document parser and minifier written in PHP",
55
"main": "index.js",
66
"directories": {

phpunit.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<phpunit bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true">
2+
<testsuites>
3+
<testsuite name="HTMLDoc">
4+
<file>tests/htmldocTest.php</file>
5+
</testsuite>
6+
<testsuite name="Find">
7+
<file>tests/findHtmldocTest.php</file>
8+
</testsuite>
9+
<testsuite name="Minify">
10+
<file>tests/minifyHtmldocTest.php</file>
11+
</testsuite>
12+
</testsuites>
13+
<filter>
14+
<whitelist processUncoveredFilesFromWhitelist="true">
15+
<directory suffix=".php">src</directory>
16+
</whitelist>
17+
</filter>
18+
<logging>
19+
<log type="coverage-clover" target="./coverage/result.xml" />
20+
<log type="coverage-html" target="./coverage/result" />
21+
<log type="coverage-text" target="./coverage/result.txt" />
22+
</logging>
23+
</phpunit>

src/htmldoc/tokens/tag.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -600,34 +600,30 @@ public function text() : array {
600600
* @return string The compiled HTML
601601
*/
602602
public function html(array $options = []) : string {
603+
$tag = $this->tagName;
603604

604605
// merge output options + custom
605-
$options = array_merge($this->root->output, $options, $this->root->output['elements'][$this->tagName] ?? []);
606+
$options = array_merge($this->root->output, $options, $this->root->output['elements'][$tag] ?? []);
606607

607608
// compile attributes
608-
$html = '<'.$this->tagName;
609+
$html = '<'.$tag;
609610
foreach ($this->attributes AS $key => $value) {
610611
$html .= ' '.$key;
611612
if ($value !== null || $options['xml']) {
612613
$empty = in_array($value, [null, ''], true);
613614

614615
// unquoted
615616
if (!$options['xml'] && $options['quotestyle'] == 'minimal' && strcspn($value, " =\"'`<>\n\r\t/") == strlen($value)) {
616-
$quote = '';
617+
$html .= '='.$value;
617618

618619
// single quotes || swap when minimal and there are double quotes in the string
619620
} elseif ($options['quotestyle'] == 'single' || ($options['quotestyle'] == 'minimal' && mb_strpos($value, '"') !== false)) {
620-
$quote = "'";
621-
$value = str_replace(['&', "'", '<'], ['&amp;', '&#39;', '&lt;'], $value);
621+
$html .= "='".str_replace(['&', "'", '<'], ['&amp;', '&#39;', '&lt;'], $value)."'";
622622

623623
// double quotes
624624
} else {
625-
$quote = '"';
626-
$value = str_replace(['&', '"', '<'], ['&amp;', '&quot;', '&lt;'], $value);
625+
$html .= '="'.str_replace(['&', '"', '<'], ['&amp;', '&quot;', '&lt;'], $value).'"';
627626
}
628-
629-
// compile
630-
$html .= '='.$quote.$value.$quote;
631627
}
632628
}
633629

@@ -642,7 +638,7 @@ public function html(array $options = []) : string {
642638
$html .= $item->html($options);
643639
}
644640
if ($options['closetags'] || $this->close) {
645-
$html .= '</'.$this->tagName.'>';
641+
$html .= '</'.$tag.'>';
646642
}
647643
}
648644
return $html;

0 commit comments

Comments
 (0)