@@ -34,6 +34,22 @@ class InlineHtmlParser extends AbstractParser
34
34
35
35
protected array $ items = [];
36
36
37
+ /**
38
+ * There is a bug with the Stillat\BladeParser\Document\Document::fromText parser.
39
+ * It doesn't parse the special characters correctly. It treats these characters
40
+ * as indentations and spaces resulting in a miscalculated Node position.
41
+ *
42
+ * This function replaces the special characters with a single, placeholder character
43
+ */
44
+ private function replaceSpecialAndEmoji (string $ text , string $ placeholder = '* ' ): string
45
+ {
46
+ return preg_replace (
47
+ '/[\x{3040}-\x{30FF}\x{4E00}-\x{9FFF}\x{1F300}-\x{1FAFF}\x{1F000}-\x{1F6FF}\x{2190}-\x{21AA}\x{2300}-\x{23FF}\x{25A0}-\x{25FF}\x{1F600}-\x{1F64F}\x{1F680}-\x{1F6FF}\x{2700}-\x{27BF}]/u ' ,
48
+ $ placeholder ,
49
+ $ text
50
+ );
51
+ }
52
+
37
53
public function parse (InlineHtml $ node )
38
54
{
39
55
if ($ node ->getStartPosition () > 0 ) {
@@ -46,7 +62,9 @@ public function parse(InlineHtml $node)
46
62
$ this ->startLine = $ range ->start ->line ;
47
63
}
48
64
49
- $ this ->parseBladeContent (Document::fromText ($ node ->getText ()));
65
+ $ this ->parseBladeContent (Document::fromText (
66
+ $ this ->replaceSpecialAndEmoji ($ node ->getText ())
67
+ ));
50
68
51
69
if (count ($ this ->items )) {
52
70
$ blade = new Blade ;
@@ -95,7 +113,7 @@ protected function doEchoParse(BaseNode $node, $prefix, $content)
95
113
}
96
114
97
115
$ range ->start ->line += $ this ->startLine + $ node ->position ->startLine - 2 ;
98
- $ range ->end ->line += $ this ->startLine + $ node ->position ->startLine - 2 ;
116
+ $ range ->end ->line += $ this ->startLine + $ node ->position ->startLine - 2 ;
99
117
100
118
return $ range ;
101
119
};
0 commit comments