Skip to content

Commit 2b09a2c

Browse files
committed
allow html in attributes (can be used with javascript)
1 parent 313952e commit 2b09a2c

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/Printer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,17 @@ protected function renderNode(Node $node, int $level): string
8181
// Process element nodes.
8282
if ($node->type === NodeType::ELEMENT) {
8383
$tagLower = strtolower($node->tag);
84-
$html = $indent . "<" . $node->tag;
84+
$html = $indent . '<' . $node->tag;
8585
foreach ($node->attributes as $name => $value) {
8686
if ($value !== null) {
87-
$html .= " " . $name . '="' . htmlspecialchars($value, ENT_QUOTES, 'UTF-8', false) . '"';
87+
$html .= ' ' . $name . '="' . $value . '"';
8888
} else {
89-
$html .= " " . $name;
89+
$html .= ' ' . $name;
9090
}
9191
}
9292
// For void elements, render in self-closing style.
9393
if (in_array($tagLower, $this->voidElements)) {
94-
$html .= " />" . $this->newline;
94+
$html .= ' />' . $this->newline;
9595

9696
return $html;
9797
}

tests/Feature/PrintTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,11 @@
109109
HTML
110110
);
111111
});
112+
113+
it('can handle html inside of attributes', function () {
114+
$html = getFixture('html-in-attributes.html');
115+
116+
$tokens = Lexer::fromString($html)->lex();
117+
$nodes = Parser::make($tokens)->parse();
118+
expect(Printer::make($nodes)->render())->toEqual($html);
119+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div>
2+
<p title="This is a title <br> With several lines!">
3+
This is a paragraph
4+
</p>
5+
</div>

0 commit comments

Comments
 (0)