diff --git a/src/Latte/Compiler/Compiler.php b/src/Latte/Compiler/Compiler.php index 7c2a36036..20eb609d1 100644 --- a/src/Latte/Compiler/Compiler.php +++ b/src/Latte/Compiler/Compiler.php @@ -441,26 +441,28 @@ private function processHtmlAttributeBegin(Token $token) $this->lastAttrValue = & $this->htmlNode->attrs[$token->name]; $this->output .= $this->escape($token->text); + $context = NULL; + $lower = strtolower($token->name); if (in_array($token->value, ['"', "'"], TRUE)) { $this->lastAttrValue = ''; $contextMain = self::CONTEXT_QUOTED_ATTRIBUTE; + if (in_array($this->contentType, [self::CONTENT_HTML, self::CONTENT_XHTML], TRUE)) { + if (Helpers::startsWith($lower, 'on')) { + $context = self::CONTENT_JS; + } elseif ($lower === 'style') { + $context = self::CONTENT_CSS; + } + } } else { $this->lastAttrValue = $token->value; $contextMain = self::CONTEXT_TAG; } - $context = NULL; - if (in_array($this->contentType, [self::CONTENT_HTML, self::CONTENT_XHTML], TRUE)) { - $lower = strtolower($token->name); - if (Helpers::startsWith($lower, 'on')) { - $context = self::CONTENT_JS; - } elseif ($lower === 'style') { - $context = self::CONTENT_CSS; - } elseif (in_array($lower, ['href', 'src', 'action', 'formaction'], TRUE) - || ($lower === 'data' && strtolower($this->htmlNode->name) === 'object') - ) { - $context = self::CONTENT_URL; - } + if (in_array($this->contentType, [self::CONTENT_HTML, self::CONTENT_XHTML], TRUE) + && (in_array($lower, ['href', 'src', 'action', 'formaction'], TRUE) + || ($lower === 'data' && strtolower($this->htmlNode->name) === 'object')) + ) { + $context = self::CONTENT_URL; } $this->setContext($contextMain, $context); diff --git a/tests/Latte/expected/macros.general.html.html b/tests/Latte/expected/macros.general.html.html index 606908fe5..2c79da588 100644 --- a/tests/Latte/expected/macros.general.html.html +++ b/tests/Latte/expected/macros.general.html.html @@ -26,7 +26,7 @@
-
+
diff --git a/tests/Latte/expected/macros.general.html.phtml b/tests/Latte/expected/macros.general.html.phtml index d7fe75bc3..f09bbda37 100644 --- a/tests/Latte/expected/macros.general.html.phtml +++ b/tests/Latte/expected/macros.general.html.phtml @@ -52,7 +52,7 @@ class Template%a% extends Latte\Runtime\Template
val2=>
->
+>
>
diff --git a/tests/Latte/expected/macros.general.xhtml.html b/tests/Latte/expected/macros.general.xhtml.html index 0e3cc386c..ae0bc5beb 100644 --- a/tests/Latte/expected/macros.general.xhtml.html +++ b/tests/Latte/expected/macros.general.xhtml.html @@ -26,7 +26,7 @@-
+
diff --git a/tests/Latte/expected/macros.general.xhtml.phtml b/tests/Latte/expected/macros.general.xhtml.phtml index a2d8c164a..ac7bdd6c6 100644 --- a/tests/Latte/expected/macros.general.xhtml.phtml +++ b/tests/Latte/expected/macros.general.xhtml.phtml @@ -54,7 +54,7 @@ class Template%a% extends Latte\Runtime\Template
val2=>
->
+>
>