From 5f2d6dfeb5620986ce334755100e2f7509d34bb0 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 14 May 2023 15:05:24 +0200 Subject: [PATCH] Added `utils.rst_to_html` action. --- platypush/plugins/utils/__init__.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/platypush/plugins/utils/__init__.py b/platypush/plugins/utils/__init__.py index 66961ea66..989f3e2b7 100644 --- a/platypush/plugins/utils/__init__.py +++ b/platypush/plugins/utils/__init__.py @@ -344,5 +344,24 @@ class UtilsPlugin(Plugin): return plugins + @action + def rst_to_html(self, text: str): + """ + Utility action to convert RST to HTML. + + It is mostly used by the frontend to render the docstring of the + available plugins and actions. + """ + try: + import docutils.core # type: ignore + except ImportError: + self.logger.warning( + "docutils is not installed. " + "Please install docutils to convert RST to HTML." + ) + return text + + return docutils.core.publish_parts(text, writer_name='html')['html_body'] + # vim:sw=4:ts=4:et: