diff --git a/src/BaseCompiler.php b/src/BaseCompiler.php index 35dae9d..18a9986 100644 --- a/src/BaseCompiler.php +++ b/src/BaseCompiler.php @@ -4,6 +4,7 @@ namespace Zoomyboy\Tex; use Illuminate\Contracts\Support\Responsable; use Illuminate\Http\File; +use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; use Log; @@ -34,6 +35,13 @@ abstract class BaseCompiler implements Responsable return $this; } + public function storeAs(string $directory, string $name, string $disk): void + { + $contents = $this->file->getContent(); + + Storage::disk($disk)->put($name, $contents); + } + public function toResponse($request) { return response()->file($this->file->getRealPath(), [ diff --git a/src/BladeCompiler.php b/src/BladeCompiler.php index ef9532b..7dcd614 100644 --- a/src/BladeCompiler.php +++ b/src/BladeCompiler.php @@ -9,4 +9,25 @@ class BladeCompiler extends BaseBladeCompiler protected $contentTags = ['<<<', '>>>']; protected $rawTags = ['<<>>']; + + protected string $slashReplace = 'GuYeuquexaeReu8uaedeel2PooYahtha'; + + public function registerEscapeDirective(): void + { + $this->directive('escape', fn ($expression) => implode('', [ + 'replace("\\\", "'.$this->slashReplace.'")', + '->replace("$", "\\\\$")', + '->replace("#", "\\\\#")', + '->replace("%", "\\\\%")', + '->replace("&", "\\\\&")', + '->replace("_", "\\\\_")', + '->replace("{", "\\\\{")', + '->replace("}", "\\\\}")', + '->replace("~", "$\\\textasciitilde$")', + '->replace("^", "$\\\textasciicircum$")', + '->replace("'.$this->slashReplace.'", "$\\\textbackslash$")', + '; ?>', + ])); + } } diff --git a/src/TexServiceProvider.php b/src/TexServiceProvider.php index 54375e0..f70ed7f 100644 --- a/src/TexServiceProvider.php +++ b/src/TexServiceProvider.php @@ -16,6 +16,7 @@ class TexServiceProvider extends ServiceProvider { view()->addExtension('tex', 'tex', function () { $compiler = new BladeCompiler(app('files'), config('view.compiled')); + $compiler->registerEscapeDirective(); return new CompilerEngine($compiler, app('files')); });