Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions app/Parsers/InlineHtmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ class InlineHtmlParser extends AbstractParser

protected array $items = [];

/**
* Stillat\BladeParser\Document\Document::fromText treats multibyte characters
* as indentations and spaces resulting in a miscalculated Node position.
*
* This function replaces the multibyte characters with a single, placeholder character
*/
private function replaceMultibyteChars(string $text, string $placeholder = '*'): string
{
return preg_replace('/[^\x00-\x7F]/u', $placeholder, $text);
}

public function parse(InlineHtml $node)
{
if ($node->getStartPosition() > 0) {
Expand All @@ -46,7 +57,9 @@ public function parse(InlineHtml $node)
$this->startLine = $range->start->line;
}

$this->parseBladeContent(Document::fromText($node->getText()));
$this->parseBladeContent(Document::fromText(
$this->replaceMultibyteChars($node->getText())
));

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

$range->start->line += $this->startLine + $node->position->startLine - 2;
$range->end->line += $this->startLine + $node->position->startLine - 2;
$range->end->line += $this->startLine + $node->position->startLine - 2;

return $range;
};
Expand Down