Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom classes tag breaks/errors when code contains function with a parameter (php) #166

Open
theokbokki opened this issue Dec 20, 2024 · 0 comments

Comments

@theokbokki
Copy link

Environment:

  • OS: MacOS Sequoia
  • PHP version: 8.3

What happens:

When there is a function with a parameter in the code surrounded by custom classes tag, I either get an error, or the argument gets cut weirdly.
For example, if I have this: {:_:function ($test) {:}, it will return this:

<span class="_"><span class="hl-keyword">function</span> ($te<span class="hl-injection">$test</span></span>) {

Which visually looks like this: function ($te$test) {

And if I add the second bracket like so {:_:function ($test) {}:}, I get this error:
image

What should happen

I expect to get this output:

<span class="_"><span class="hl-keyword">function</span> (<span class="hl-injection">$test</span>) {}</span>

Steps to reproduce:

  1. Create a new Tempest project with composer create-project tempest/app my-app --stability alpha
  2. Copy this in HomeController
<?php

declare(strict_types=1);

namespace App;

use Tempest\Highlight\Highlighter;
use Tempest\Http\Get;

use function Tempest\view;

use Tempest\View\View;

final readonly class HomeController
{
    #[Get('/')]
    public function __invoke(): View
    {
        // To show the error, put this in the 'CODE' string: `{:_:function ($test) {}:}`
        $code = (new Highlighter())->parse(
                <<<'CODE'
                {:_:function ($test) {:}
                CODE,
                'php'
            );

        return view('home.view.php')->data(code: $code);
    }
}
  1. Copy this in home.view.php
<html lang="en">
<head>
    <title>Tempest</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="/main.css" rel="stylesheet">
</head>
<body class="flex justify-center items-center">
<div>
{!! $code !!}
</div>
</body>
</html>
  1. Run ./tempest serve

Additional context:

  • Everything works fine when you remove the custom classes tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant