Skip to content

Commit b925b14

Browse files
committed
format
1 parent 1a1ba1a commit b925b14

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

app/Support/Markdown.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Illuminate\Support\HtmlString;
77
use League\CommonMark\Environment\Environment;
88
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
9+
use League\CommonMark\Extension\Embed\Bridge\OscaroteroEmbedAdapter;
10+
use League\CommonMark\Extension\Embed\EmbedExtension;
911
use League\CommonMark\Extension\HeadingPermalink\HeadingPermalinkExtension;
1012
use League\CommonMark\Extension\Table\TableExtension;
1113
use League\CommonMark\Extension\TableOfContents\TableOfContentsExtension;
@@ -17,10 +19,15 @@ class Markdown implements Htmlable, Stringable
1719
{
1820
protected Environment $environment;
1921

20-
public function __construct(protected string $content, bool $hasTableOfContents = true)
22+
public function __construct(protected string $content, bool $hasTableOfContents = true, protected bool $shouldSanitize = true)
2123
{
2224
$this->environment = new Environment([
2325
'allow_unsafe_links' => false,
26+
'embed' => [
27+
'adapter' => new OscaroteroEmbedAdapter,
28+
'allowed_domains' => ['youtube.com', 'youtube-nocookie.com'],
29+
'fallback' => 'link',
30+
],
2431
'heading_permalink' => [
2532
'html_class' => 'heading-anchor',
2633
'id_prefix' => '',
@@ -40,6 +47,7 @@ public function __construct(protected string $content, bool $hasTableOfContents
4047
]);
4148

4249
$this->environment->addExtension(new CommonMarkCoreExtension);
50+
$this->environment->addExtension(new EmbedExtension);
4351
$this->environment->addExtension(new TableExtension);
4452
$this->environment->addExtension(new HeadingPermalinkExtension);
4553
$this->environment->addExtension(new TorchlightExtension);
@@ -49,9 +57,9 @@ public function __construct(protected string $content, bool $hasTableOfContents
4957
}
5058
}
5159

52-
public static function parse(string $text, bool $hasTableOfContents = true): static
60+
public static function parse(string $text, bool $hasTableOfContents = true, bool $shouldSanitize = true): static
5361
{
54-
$static = app(static::class, ['content' => $text, 'hasTableOfContents' => $hasTableOfContents]);
62+
$static = app(static::class, ['content' => $text, 'hasTableOfContents' => $hasTableOfContents, 'shouldSanitize' => $shouldSanitize]);
5563

5664
$static->convert();
5765
$static->removeH1Tags();
@@ -143,6 +151,10 @@ public function convertVideoToHtml(): static
143151

144152
public function __toString(): string
145153
{
154+
if (! $this->shouldSanitize) {
155+
return $this->content;
156+
}
157+
146158
return str($this->content)->sanitizeHtml();
147159
}
148160

content/articles/leandrocfe-whats-new-in-filament-v4.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ There are many new features and improvements in Filament v4 Beta, but here are s
2828
- [**Improved bulk action system**](#bulk-actions): Authorize individual records in bulk actions, use notifications to inform users of bulk action results with success and failure counts grouped by failure reason, and benefit from improved performance through chunked processing of selected records.
2929
- [**Restructured documentation**](https://filamentphp.com/docs/4.x): The Filament documentation has been restructured to provide a clearer overview of the features and how they work together. The new documentation includes more examples, cross-references, and explanations of how features work internally.
3030

31+
[Dennis Koch](https://github.com/pxlrbt) gave a great presentation demoing and explaining many of these new features recently. You can watch it here:
32+
33+
<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/8qyV696TALA?si=sOAf8O5vrW8aQ3ny" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
34+
3135
## General
3236

3337
### Improved performance

resources/views/articles/view-article.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class="select-none rounded-full bg-stone-200/50 px-5 py-2.5 text-sm"
101101
<div
102102
class="prose selection:bg-stone-500/30 prose-a:break-words prose-blockquote:not-italic prose-code:break-words prose-code:rounded prose-code:bg-merino prose-code:px-1.5 prose-code:py-0.5 prose-code:font-normal prose-code:before:hidden prose-code:after:hidden [&_p]:before:hidden [&_p]:after:hidden"
103103
>
104-
{!! \App\Support\Markdown::parse($article->content, hasTableOfContents: false) !!}
104+
{!! \App\Support\Markdown::parse($article->content, hasTableOfContents: false, shouldSanitize: false) !!}
105105
</div>
106106
</div>
107107
</div>

0 commit comments

Comments
 (0)