diff --git a/extensions/plugi-ext-blog/README.md b/extensions/plugi-ext-blog/README.md index 298a1d6..5cf86fc 100644 --- a/extensions/plugi-ext-blog/README.md +++ b/extensions/plugi-ext-blog/README.md @@ -20,6 +20,6 @@ Keep `/blog` and `/blog/{slug}` unique among the site’s page routes. ## Authoring content and images -Write post bodies in Markdown. The detail page supports headings, paragraphs and line breaks, bold and italic text, inline code, links, and ordered or unordered lists. Raw HTML is displayed as text; links only render with relative URLs or `http`, `https`, and `mailto` schemes. +Write post bodies in Markdown using the syntax-highlighted source editor. Its toolbar inserts bold, italic, headings, links, unordered and ordered lists, blockquotes, horizontal rules, inline code, and fenced code blocks; the live preview uses the same server-side renderer as the public detail page. If JavaScript is unavailable, the source textarea remains usable and can still save the post. The detail page supports headings, paragraphs and line breaks, bold and italic text, inline code, links, ordered and unordered lists, blockquotes, horizontal rules, and fenced code blocks. Code-block contents are displayed as escaped text. Raw HTML is displayed as text; links only render with relative URLs or `http`, `https`, and `mailto` schemes. Choose a featured image from the existing Website Manager media library to show it on post cards and detail pages. Use the editor’s inline-image selector to insert Markdown image syntax at the body cursor; image alt text comes from the selected media item. Inline images render only with relative, `http`, or `https` sources. Unsafe link and image protocols are not rendered. \ No newline at end of file diff --git a/extensions/plugi-ext-blog/admin/Classes/PostContentRenderer.php b/extensions/plugi-ext-blog/admin/Classes/PostContentRenderer.php index dfdaae2..86b6784 100644 --- a/extensions/plugi-ext-blog/admin/Classes/PostContentRenderer.php +++ b/extensions/plugi-ext-blog/admin/Classes/PostContentRenderer.php @@ -11,7 +11,8 @@ class PostContentRenderer $paragraph = []; $listType = null; $listItems = []; - $flush = function () use (&$blocks, &$paragraph, &$listType, &$listItems): void { + $quote = []; + $flush = function () use (&$blocks, &$paragraph, &$listType, &$listItems, &$quote): void { if ($paragraph !== []) { $blocks[] = '
' . nl2br($this->renderInline(implode("\n", $paragraph))) . '
'; $paragraph = []; @@ -23,9 +24,35 @@ class PostContentRenderer $listType = null; $listItems = []; } + if ($quote !== []) { + $blocks[] = ''; + $quote = []; + } }; + $fence = null; + $codeLines = []; foreach (preg_split('/\R/', $markdown) ?: [] as $line) { + if ($fence !== null) { + if (preg_match('/^ {0,3}(`{3,}|~{3,})[ \t]*$/', $line, $matches) + && $matches[1][0] === $fence[0] + && strlen($matches[1]) >= strlen($fence)) { + $blocks[] = '' . nl2br($this->renderInline(implode("\n", $quote))) . '
' . $this->escape(implode("\n", $codeLines)) . '';
+ $fence = null;
+ $codeLines = [];
+ continue;
+ }
+ $codeLines[] = $line;
+ continue;
+ }
+
+ if (preg_match('/^ {0,3}(`{3,}|~{3,})(.*)$/', $line, $matches)) {
+ $flush();
+ $fence = $matches[1];
+ $codeLines = [];
+ continue;
+ }
+
if (trim($line) === '') {
$flush();
continue;
@@ -45,6 +72,23 @@ class PostContentRenderer
continue;
}
+ if (preg_match('/^ {0,3}(?:(?:\*[ \t]*){3,}|(?:-[ \t]*){3,}|(?:_[ \t]*){3,})$/', $line)) {
+ $flush();
+ $blocks[] = '' . $this->escape(implode("\n", $codeLines)) . '';
+ }
return implode("\n", $blocks);
}
diff --git a/extensions/plugi-ext-blog/admin/Views/EditPost.php b/extensions/plugi-ext-blog/admin/Views/EditPost.php
index c0c2e98..65d033b 100644
--- a/extensions/plugi-ext-blog/admin/Views/EditPost.php
+++ b/extensions/plugi-ext-blog/admin/Views/EditPost.php
@@ -57,29 +57,64 @@ $imageUploads = array_values(array_filter((new UploadRepository())->getAll(), st
- Use Markdown for headings, links, lists, and emphasis.
-Alt text comes from the media library; the image Markdown is inserted at the cursor.
+Use Markdown for headings, lists, quotes, rules, code blocks, links, and emphasis.
+Alt text comes from the media library; the image Markdown is inserted at the cursor.
+Rendered like the published post.
+Waiting for the preview…
+t;){let n=!0,u=!1;if(!l||c>a[l-1].to){let e=L[c-1];e!=s&&(n=!1,u=e==16)}let d=!n&&s==1?[]:null,f=n?r:r+1,p=c;e:for(;;)if(l&&p==a[l-1].to){if(u)break;let m=a[--l];if(!n)for(let e=m.from,n=l;;){if(e==t)break e;if(n&&a[n-1].to==e)e=a[--n].from;else if(L[e-1]==s)break e;else break}d?d.push(m):(m.to{if(t>e&&tt(e)),n.from,t.head>n.from?-1:1);return r==n.from?n:w.cursor(r,r=s&&this.right.forEachLine(e,t,n,o,s,a);else{let c=this.lineAt(s,B.ByPos,n,r,i);e