Skip to content

Commit 1693a4a

Browse files
committed
Add handleHtml
1 parent 92a653f commit 1693a4a

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/Compiler.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public function convertNode(DOMNode $node, int $level = 0): DOMNode
149149
$this->replaceShowWithIf($node);
150150
$this->handleIf($node);
151151
$this->handleFor($node);
152+
$this->handleHtml($node);
152153
$this->stripEventHandlers($node);
153154
//$this->handleRawHtml($node, $data);
154155
$this->handleDefaultSlot($node);
@@ -521,6 +522,21 @@ private function handleFor(DOMElement $node)
521522
$node->removeAttribute('v-for');
522523
}
523524

525+
private function handleHtml(DOMElement $node)
526+
{
527+
if (!$node->hasAttribute('v-html')) {
528+
return;
529+
}
530+
531+
$html = $node->getAttribute('v-html');
532+
$node->removeAttribute('v-html');
533+
while ($node->hasChildNodes()) {
534+
$node->removeChild($node->firstChild);
535+
}
536+
$node->appendChild(new DOMText('{{ ' . $html . '|raw }}'));
537+
}
538+
539+
524540
protected function addDefaultsToVariable($varName, $string): string
525541
{
526542
if (!in_array($varName, array_keys($this->properties))) {

tests/fixtures/vue-html/html.twig

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{% set rawHtml = '<strong>text</strong>' %}
2-
<template>
3-
<div>
4-
<span>
5-
{{ rawHtml|raw }}
6-
</span>
7-
</div>
8-
</template>
2+
<div class="{{class|default('')}}">
3+
<span>
4+
{{ rawHtml|raw }}
5+
</span>
6+
</div>

tests/fixtures/vue-html/html.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</template>
66

77
<twig>
8-
{% set rawHtml = '<strong>text</strong>' %}
8+
{% set rawHtml = '&lt;strong&gt;text&lt;/strong&gt;' %}
99
</twig>
1010

1111
<script>

0 commit comments

Comments
 (0)