Skip to content

Commit c4c984d

Browse files
Merge pull request #19 from N1ebieski/Fix-Links-in-blade-views-are-misplaced-after-multibyte-characters-#9
Fix Links in blade views are misplaced after multibyte characters
2 parents b26c66d + a9c56f6 commit c4c984d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

app/Parsers/InlineHtmlParser.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ class InlineHtmlParser extends AbstractParser
3434

3535
protected array $items = [];
3636

37+
/**
38+
* Stillat\BladeParser\Document\Document::fromText treats multibyte characters
39+
* as indentations and spaces resulting in a miscalculated Node position.
40+
*
41+
* This function replaces the multibyte characters with a single, placeholder character
42+
*/
43+
private function replaceMultibyteChars(string $text, string $placeholder = '*'): string
44+
{
45+
return preg_replace('/[^\x00-\x7F]/u', $placeholder, $text);
46+
}
47+
3748
public function parse(InlineHtml $node)
3849
{
3950
if ($node->getStartPosition() > 0) {
@@ -46,7 +57,9 @@ public function parse(InlineHtml $node)
4657
$this->startLine = $range->start->line;
4758
}
4859

49-
$this->parseBladeContent(Document::fromText($node->getText()));
60+
$this->parseBladeContent(Document::fromText(
61+
$this->replaceMultibyteChars($node->getText())
62+
));
5063

5164
if (count($this->items)) {
5265
$blade = new Blade;
@@ -95,7 +108,7 @@ protected function doEchoParse(BaseNode $node, $prefix, $content)
95108
}
96109

97110
$range->start->line += $this->startLine + $node->position->startLine - 2;
98-
$range->end->line += $this->startLine + $node->position->startLine - 2;
111+
$range->end->line += $this->startLine + $node->position->startLine - 2;
99112

100113
return $range;
101114
};

0 commit comments

Comments
 (0)