Skip to content
Open
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
24 changes: 21 additions & 3 deletions app/Parsers/InlineHtmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ private function replaceMultibyteChars(string $text, string $placeholder = '*'):
return preg_replace('/[^\x00-\x7F]/u', $placeholder, $text);
}

private function createDocument(string $text): Document
{
// First, we need to parse the text with the multibyte characters
$document = Document::fromText($text);

// Then, we need to parse the text with multibyte characters replaced by placeholders
// because Stillat\BladeParser\Document\Document::fromText treats multibyte characters
// as indentations and spaces resulting in a miscalculated Node position
$documentWithPlaceholders = Document::fromText($this->replaceMultibyteChars($text));

// Finally, we need to update the Node positions from original text
$nodesWithPlaceholders = $documentWithPlaceholders->getNodes();

foreach ($document->getNodes() as $index => $node) {
$node->position = $nodesWithPlaceholders[$index]->position;
}

return $document;
}

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

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

if (count($this->items)) {
$blade = new Blade;
Expand Down