Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c4c984d

Browse filesBrowse 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
Copy full SHA for c4c984d

File tree

1 file changed

+15
-2
lines changed
Filter options

1 file changed

+15
-2
lines changed

‎app/Parsers/InlineHtmlParser.php

Copy file name to clipboardExpand all lines: app/Parsers/InlineHtmlParser.php
+15-2
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.