diff options
| author | Bnyro <bnyro@tutanota.com> | 2023-09-08 08:40:22 +0200 |
|---|---|---|
| committer | Markus Heiser <markus.heiser@darmarIT.de> | 2023-09-08 11:47:13 +0200 |
| commit | a3d7e9c285d8c5947c9cb67b1587e7732ac4bc90 (patch) | |
| tree | a4cf8c00e667f9cf558f0cf44b1d72248b2e1e1d /searx/engines | |
| parent | 668b1d55abb7fe0b8afea8e96de7e844e679586b (diff) | |
[mod] utils.py: add markdown_to_text helper function
Diffstat (limited to 'searx/engines')
| -rw-r--r-- | searx/engines/lemmy.py | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/searx/engines/lemmy.py b/searx/engines/lemmy.py index 8c1b22151..bc3cc9cf6 100644 --- a/searx/engines/lemmy.py +++ b/searx/engines/lemmy.py @@ -42,10 +42,9 @@ Implementations from datetime import datetime from urllib.parse import urlencode -from markdown_it import MarkdownIt from flask_babel import gettext -from searx.utils import html_to_text +from searx.utils import markdown_to_text about = { "website": 'https://lemmy.ml/', @@ -78,11 +77,6 @@ def request(query, params): return params -def _format_content(content): - html = MarkdownIt("commonmark", {"typographer": True}).enable(["replacements", "smartquotes"]).render(content) - return html_to_text(html) - - def _get_communities(json): results = [] @@ -97,7 +91,7 @@ def _get_communities(json): { 'url': result['community']['actor_id'], 'title': result['community']['title'], - 'content': _format_content(result['community'].get('description', '')), + 'content': markdown_to_text(result['community'].get('description', '')), 'img_src': result['community'].get('icon', result['community'].get('banner')), 'publishedDate': datetime.strptime(counts['published'][:19], '%Y-%m-%dT%H:%M:%S'), 'metadata': metadata, @@ -114,7 +108,7 @@ def _get_users(json): { 'url': result['person']['actor_id'], 'title': result['person']['name'], - 'content': _format_content(result['person'].get('bio', '')), + 'content': markdown_to_text(result['person'].get('bio', '')), } ) @@ -140,7 +134,7 @@ def _get_posts(json): content = result['post'].get('body', '').strip() if content: - content = _format_content(content) + content = markdown_to_text(content) results.append( { @@ -164,7 +158,7 @@ def _get_comments(json): content = result['comment'].get('content', '').strip() if content: - content = _format_content(content) + content = markdown_to_text(content) metadata = ( f"▲ {result['counts']['upvotes']} ▼ {result['counts']['downvotes']}" @@ -176,7 +170,7 @@ def _get_comments(json): { 'url': result['comment']['ap_id'], 'title': result['post']['name'], - 'content': _format_content(result['comment']['content']), + 'content': markdown_to_text(result['comment']['content']), 'publishedDate': datetime.strptime(result['comment']['published'][:19], '%Y-%m-%dT%H:%M:%S'), 'metadata': metadata, } |