Posts module: posts, drafts and scheduling, categories and tags

This commit is contained in:
Matthijs Iriks committed 2026-12-04 01:33:59 +01:00
1 parent a9a1625241
commit e093614169
18 files changed
+977 -30

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
<?php
namespace IriksIT\Manager\Support;
use Illuminate\Support\Str;
use League\CommonMark\Extension\ExternalLink\ExternalLinkExtension;
/**
* Posts are written in Markdown. Raw HTML in a post is escaped, so the rendered output is safe
* to print. Links to other hosts open in a new window; `manager.markdown.internal_hosts` lists
* more hosts that count as this site.
*/
final class Markdown
{
public static function toHtml(string $markdown): string
{
$host = parse_url((string) config('app.url'), PHP_URL_HOST);
return Str::markdown($markdown, [
'html_input' => 'escape',
'allow_unsafe_links' => false,
'external_link' => [
'internal_hosts' => array_values(array_filter([$host, ...(array) config('manager.markdown.internal_hosts', [])])),
'open_in_new_window' => true,
'noopener' => 'external',
'noreferrer' => 'external',
],
], [new ExternalLinkExtension]);
}
public static function toPlainText(string $markdown): string
{
$text = strip_tags(self::toHtml($markdown));
return trim((string) preg_replace('/\s+/', ' ', html_entity_decode($text, ENT_QUOTES | ENT_HTML5)));
}
}