From db42ade2b61c553ee3f262044272f11ae78b51a0 Mon Sep 17 00:00:00 2001 From: Phablulo Date: Sun, 16 Jan 2022 15:37:38 -0300 Subject: [PATCH] [PLUGIN][MarkdownNotes] add markdown support for notes --- plugins/MarkdownNotes/MarkdownNotes.php | 56 +++++++++++++++++++++++++ plugins/MarkdownNotes/composer.json | 5 +++ 2 files changed, 61 insertions(+) create mode 100644 plugins/MarkdownNotes/MarkdownNotes.php create mode 100644 plugins/MarkdownNotes/composer.json diff --git a/plugins/MarkdownNotes/MarkdownNotes.php b/plugins/MarkdownNotes/MarkdownNotes.php new file mode 100644 index 0000000000..7b5bbe426c --- /dev/null +++ b/plugins/MarkdownNotes/MarkdownNotes.php @@ -0,0 +1,56 @@ +. +// }}} +/** + * Markdown note support for GNU social + * + * @package GNUsocial + * @category Plugin + * + * @author Phablulo + * @copyright 2018-2019, 2021 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later + */ + +namespace Plugin\MarkdownNotes; + +use App\Core\Event; +use App\Core\Modules\Plugin; +use Parsedown; + +class MarkdownNotes extends Plugin +{ + public function onPostingAvailableContentTypes(array &$types): bool + { + $types['Markdown'] = 'text/markdown'; + return Event::next; + } + public function onRenderNoteContent($content, $content_type, &$rendered): bool + { + if ($content_type !== 'text/markdown') { + return Event::next; + } + // https://github.com/erusev/parsedown + $Parsedown = new Parsedown(); + $Parsedown->setSafeMode(true); + $rendered = $Parsedown->text($content); + return Event::stop; + } +} diff --git a/plugins/MarkdownNotes/composer.json b/plugins/MarkdownNotes/composer.json new file mode 100644 index 0000000000..f7b79e5ccf --- /dev/null +++ b/plugins/MarkdownNotes/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "erusev/parsedown": "^1.7.4" + } +}