From 9e4aed84f82483103df2c6a2f40d06d97bfe7a4f Mon Sep 17 00:00:00 2001 From: Phablulo Date: Sun, 16 Jan 2022 16:24:56 -0300 Subject: [PATCH] [PLUGIN][LatexNotes] add LaTeX support for notes --- plugins/LatexNotes/LatexNotes.php | 60 +++++++++++++++++++++++++++++++ plugins/LatexNotes/composer.json | 5 +++ 2 files changed, 65 insertions(+) create mode 100644 plugins/LatexNotes/LatexNotes.php create mode 100644 plugins/LatexNotes/composer.json diff --git a/plugins/LatexNotes/LatexNotes.php b/plugins/LatexNotes/LatexNotes.php new file mode 100644 index 0000000000..ddbe7f333a --- /dev/null +++ b/plugins/LatexNotes/LatexNotes.php @@ -0,0 +1,60 @@ +. +// }}} +/** + * LaTeX 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\LatexNotes; + +use App\Core\Event; +use App\Core\Modules\Plugin; +use PhpLatex_Parser; +use PhpLatex_Renderer_Html; + +class LatexNotes extends Plugin +{ + public function onPostingAvailableContentTypes(array &$types): bool + { + $types['LaTeX'] = 'application/x-latex'; + return Event::next; + } + public function onRenderNoteContent($content, $content_type, &$rendered): bool + { + if ($content_type !== 'application/x-latex') { + return Event::next; + } + // https://github.com/xemlock/php-latex + $parser = new PhpLatex_Parser(); + $parsedTree = $parser->parse($content); + + $htmlRenderer = new PhpLatex_Renderer_Html(); + $rendered = $htmlRenderer->render($parsedTree); + + return Event::stop; + } +} diff --git a/plugins/LatexNotes/composer.json b/plugins/LatexNotes/composer.json new file mode 100644 index 0000000000..7d11d94567 --- /dev/null +++ b/plugins/LatexNotes/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "xemlock/php-latex": "dev-master" + } +}