forked from laysense/laysense.cn
Add canvas element tools and categorized article editing
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user