Add escape directive
This commit is contained in:
parent
5a68cce19e
commit
c0e77ec198
|
@ -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(), [
|
||||
|
|
|
@ -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('', [
|
||||
'<?php echo str('.$expression.')',
|
||||
'->replace("\\\", "'.$this->slashReplace.'")',
|
||||
'->replace("$", "\\\\$")',
|
||||
'->replace("#", "\\\\#")',
|
||||
'->replace("%", "\\\\%")',
|
||||
'->replace("&", "\\\\&")',
|
||||
'->replace("_", "\\\\_")',
|
||||
'->replace("{", "\\\\{")',
|
||||
'->replace("}", "\\\\}")',
|
||||
'->replace("~", "$\\\textasciitilde$")',
|
||||
'->replace("^", "$\\\textasciicircum$")',
|
||||
'->replace("'.$this->slashReplace.'", "$\\\textbackslash$")',
|
||||
'; ?>',
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'));
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue