Add canvas element tools and categorized article editing

This commit is contained in:
2026-11-21 22:24:58 +08:00
parent 6efcdefadf
commit a5b3408358
45 changed files with 1607 additions and 660 deletions
+7 -2
View File
@@ -7,7 +7,7 @@ namespace App\Content;
use DOMDocument;
use DOMElement;
use DOMNode;
use League\CommonMark\CommonMarkConverter;
use League\CommonMark\GithubFlavoredMarkdownConverter;
use RuntimeException;
final class Html
@@ -43,13 +43,18 @@ final class Html
public static function markdown(string $text): string
{
static $converter;
$converter ??= new CommonMarkConverter(['html_input' => 'strip', 'allow_unsafe_links' => false, 'max_nesting_level' => 30]);
$converter ??= new GithubFlavoredMarkdownConverter(['html_input' => 'strip', 'allow_unsafe_links' => false, 'max_nesting_level' => 30]);
$html = $converter->convert($text)->getContent();
return str_replace(['<h1>', '</h1>'], ['<h2>', '</h2>'], $html);
}
public static function articleBody(array $article): string
{
return $article['body_format'] === 'html' ? self::sanitize($article['body']) : self::markdown($article['body']);
}
public static function applyCanvasEdits(string $body, array $edits): string
{
if (!array_is_list($edits) || count($edits) > 512) {