<?php

namespace App\Providers;

use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;

class MathServiceProvider extends ServiceProvider
{
    public function boot()
    {
        // 注册 blade directive
        Blade::directive('math', function ($expression) {
            return "<?php
                \$content = {$expression};
                // 强制通过处理器进行标准化
                \$processedContent = \\App\\Services\\MathFormulaProcessor::processFormulas(\$content);
                // 直接输出内容，让 auto-render 扩展去解析
                echo '<span class=\"math-render\">' . \$processedContent . '</span>';
            ?>";
        });
    }

    public function register()
    {
        //
    }
}