Convert markdown formatted posts to html

merge-requests/30/head
Bob Mottram 2023-03-06 12:08:25 +00:00
parent 1acf4987ac
commit 636ca0e7ec
2 changed files with 29 additions and 0 deletions

View File

@ -108,6 +108,7 @@ from utils import is_dm
from utils import is_reply
from utils import has_actor
from httpsig import message_content_digest
from posts import convert_post_content_to_html
from posts import edited_post_filename
from posts import save_post_to_box
from posts import is_create_inside_announce
@ -1484,6 +1485,7 @@ def receive_edit_to_post(recent_posts_cache: {}, message_json: {},
if not post_filename:
print('EDITPOST: ' + message_id + ' has already expired')
return False
convert_post_content_to_html(message_json)
if not _valid_post_content(base_dir, nickname, domain,
message_json, max_mentions, max_emoji,
allow_local_network_access, debug,
@ -4569,6 +4571,7 @@ def _inbox_after_initial(server, inbox_start_time,
json_obj = None
domain_full = get_full_domain(domain, port)
convert_post_content_to_html(post_json_object)
if _valid_post_content(base_dir, nickname, domain,
post_json_object, max_mentions, max_emoji,
allow_local_network_access, debug,

View File

@ -103,6 +103,31 @@ from video import convert_video_to_note
from context import get_individual_post_context
from maps import geocoords_from_map_link
from keys import get_person_key
from markdown import markdown_to_html
def convert_post_content_to_html(message_json: {}) -> None:
"""Convert post content to html
"""
obj_json = message_json
if has_object_dict(message_json):
obj_json = message_json['object']
if not obj_json.get('mediaType'):
return
if not obj_json.get('content'):
return
if obj_json['mediaType'] == 'text/markdown':
content_str = obj_json['content']
obj_json['content'] = markdown_to_html(content_str)
obj_json['mediaType'] = 'text/html'
if obj_json.get('contentMap'):
langs_dict = obj_json['contentMap']
if isinstance(langs_dict, dict):
for lang, content_str in langs_dict.items():
if not isinstance(content_str, str):
continue
obj_json['contentMap'][lang] = \
markdown_to_html(content_str)
def is_moderator(base_dir: str, nickname: str) -> bool:
@ -5463,6 +5488,7 @@ def download_announce(session, base_dir: str, http_prefix: str,
person_cache):
return None
# Check the content of the announce
convert_post_content_to_html(announced_json)
content_str = announced_json['content']
using_content_map = False
if 'contentMap' in announced_json: