Skip to content

Commit

Permalink
Allow numbers in tag names
Browse files Browse the repository at this point in the history
  • Loading branch information
assertchris committed Oct 23, 2018
1 parent 7012018 commit 9d68c67
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions source/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function tokens($code)
continue;
}

preg_match("#^</?[a-zA-Z.]#", substr($code, $cursor, 3), $matchesStart);
preg_match("#^</?[0-9a-zA-Z.]#", substr($code, $cursor, 3), $matchesStart);

if (
count($matchesStart)
Expand Down Expand Up @@ -174,7 +174,7 @@ public function tokens($code)
$tokens[] = $token;

if (preg_match("#/>$#", $tag)) {
preg_match("#<([a-zA-Z.\-_]+)#", $tag, $matchesName);
preg_match("#<([0-9a-zA-Z.\-_]+)#", $tag, $matchesName);

$previous = $tokens[count($tokens) - 1];
$tokens[count($tokens) - 1]["value"] = trim(substr($previous["value"], 0, strlen($previous["value"]) - 2)) . ">";
Expand Down Expand Up @@ -221,7 +221,7 @@ public function nodes($tokens)
$token =& $tokens[$cursor];

if ($token["type"] === "tag" && $token["value"][1] !== "/") {
preg_match("#^<([a-zA-Z.\-_]+)#", $token["value"], $matches);
preg_match("#^<([0-9a-zA-Z.\-_]+)#", $token["value"], $matches);

if ($current !== null) {
$token["parent"] =& $current;
Expand All @@ -241,7 +241,7 @@ public function nodes($tokens)
}
}
} elseif ($token["type"] === "tag" && $token["value"][1] === "/") {
preg_match("#^</([a-zA-Z.\-_]+)#", $token["value"], $matches);
preg_match("#^</([0-9a-zA-Z.\-_]+)#", $token["value"], $matches);

$name = str_replace(".", "\\", $matches[1]);

Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/compile/can-compile.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ function Error($props)
render("span", [
"className" => "icon"
]),
render("h4", [
"children" => "Error"
]),
"You forgot the",
$props->name,
"field"
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/compile/can-compile.pre
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function Error($props) {
}}
>
<span className={"icon"}></span>
<h4>Error</h4>
You forgot the {$props->name} field
</div>
);
Expand Down

0 comments on commit 9d68c67

Please sign in to comment.