summaryrefslogtreecommitdiff
path: root/searx/infopage
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2022-04-06 15:49:50 +0200
committerMarkus Heiser <markus.heiser@darmarit.de>2022-04-06 15:49:50 +0200
commit921528123263e03002682399df055f50aa891b82 (patch)
tree8a468107637c3fef5e8f7c63bf48d2a4cc421e53 /searx/infopage
parentfcb626dedd3965de4fa6c95c47a34fdd14348afd (diff)
downloadsearxng-921528123263e03002682399df055f50aa891b82.tar.gz
searxng-921528123263e03002682399df055f50aa891b82.zip
[mod] replace Markdown parser mistletoe by markdown-it-py
There are several reasons why we should prefer markdown-it-py over mistletoe: - Get identical rendering results in SearXNG's `/info` pages and the SearXNG's project documentation which is build by Sphinx-doc. In the Sphinx-doc we use the MyST parser to render Markdown and the MyST parser itself is built on top of the markdown-it-py package. - markdown-it-py has a typographer that supports *replacements* and *smartquotes* (e.g. em-dash, copyright, ellipsis, ...) [1] - markdown-it-py is much more flexible compared to mistletoe [2] - markdown-it-py is the fastest CommonMark compliant parser in python [3] [1] https://markdown-it-py.readthedocs.io/en/latest/using.html#typographic-components [2] https://markdown-it-py.readthedocs.io/en/latest/plugins.html [3] https://markdown-it-py.readthedocs.io/en/latest/other.html#performance Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/infopage')
-rw-r--r--searx/infopage/__init__.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/searx/infopage/__init__.py b/searx/infopage/__init__.py
index 44f3bdbd7..143f523d8 100644
--- a/searx/infopage/__init__.py
+++ b/searx/infopage/__init__.py
@@ -29,7 +29,7 @@ import typing
import urllib.parse
import jinja2
from flask.helpers import url_for
-import mistletoe
+from markdown_it import MarkdownIt
from .. import get_setting
from ..compat import cached_property
@@ -71,13 +71,17 @@ class InfoPage:
@cached_property
def html(self):
- """Render Markdown (CommonMark_) to HTML by using mistletoe_.
+ """Render Markdown (CommonMark_) to HTML by using markdown-it-py_.
.. _CommonMark: https://commonmark.org/
- .. _mistletoe: https://github.com/miyuchina/mistletoe
+ .. _markdown-it-py: https://github.com/executablebooks/markdown-it-py
"""
- return mistletoe.markdown(self.content)
+ return MarkdownIt(
+ "commonmark", {"typographer": True}
+ ).enable(
+ ["replacements", "smartquotes"]
+ ).render(self.content)
def get_ctx(self): # pylint: disable=no-self-use
"""Jinja context to render :py:obj:`InfoPage.content`"""