Skip to content

Commit

Permalink
Merge pull request #118 from lara-zeus/bolt-parser
Browse files Browse the repository at this point in the history
add Content parser
  • Loading branch information
atmonshi authored Jul 14, 2023
2 parents 60fe572 + c3af812 commit d04f56e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
10 changes: 10 additions & 0 deletions config/zeus-sky.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,14 @@
* \LaraZeus\Sky\Classes\MarkdownEditor::class,
*/
'editor' => \LaraZeus\Sky\Classes\TinyEditor::class,

/**
* parse the content
* you can add any parser to do str_replace or any other operation:
*
* to render Blot form by it slug: \LaraZeus\Sky\Classes\BoltParser::class,
*/
'parsers' => [
\LaraZeus\Sky\Classes\BoltParser::class,
],
];
26 changes: 26 additions & 0 deletions src/Classes/BoltParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace LaraZeus\Sky\Classes;

use Illuminate\Support\Facades\Blade;

class BoltParser
{
public function __invoke(string $content): string
{
if (class_exists(\LaraZeus\Bolt\Facades\Bolt::class)) {
$content = html_entity_decode($content);
preg_match('/<bolt>(.*?)<\/bolt>/s', $content, $bolt);
if (is_array($bolt) && isset($bolt[1])) {
$formSlug = trim($bolt[1]);
$checkForm = config('zeus-bolt.models.Form')::where('slug', $formSlug)->first();
if ($checkForm !== null) {
$boltComponent = Blade::render('<livewire:bolt.fill-form slug="' . $formSlug . '" />');
$content = str_replace('<bolt>' . $formSlug . '</bolt>', $boltComponent, $content);
}
}
}

return $content;
}
}
1 change: 0 additions & 1 deletion src/Classes/TipTapEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Filament\Forms\Components\Component;
use Filament\Forms\Components\Textarea;
use FilamentTiptapEditor\Exceptions\InvalidOutputFormatException;
use FilamentTiptapEditor\TiptapEditor as TipTapEditorAlias;

class TipTapEditor implements ContentEditor
Expand Down
15 changes: 14 additions & 1 deletion src/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ protected function requirePassword(): Attribute

public function getContent(): string
{
return config('zeus-sky.editor')::render($this->content);
return $this->parseContent(config('zeus-sky.editor')::render($this->content));
}

public function parseContent($content): string
{
$parsers = config('zeus-sky.parsers');

if (! empty($parsers)) {
foreach ($parsers as $parser) {
$content = (new $parser)($content);
}
}

return $content;
}
}

0 comments on commit d04f56e

Please sign in to comment.