From c42950f7331bf7f85310367c961d5c6bb12106d6 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 7 Sep 2018 18:31:42 +0200 Subject: [PATCH] Aggiunti embed di YouTube alla Wiki (Non attivi nelle bio) --- webserver.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/webserver.py b/webserver.py index 351b8a5b..0bca9d41 100644 --- a/webserver.py +++ b/webserver.py @@ -9,6 +9,7 @@ import telegram import query_discord_music import random import difflib +import re app = Flask(__name__) @@ -227,9 +228,15 @@ def page_wiki(key: str): db_session.close() if wiki_page is None: return render_template("wiki.html", key=key, config=config) - converted_md = Markup(markdown2.markdown(wiki_page.content.replace("<", "<"), - extras=["spoiler", "tables", "smarty-pants", "fenced-code-blocks"])) - return render_template("wiki.html", key=key, wiki_page=wiki_page, converted_md=converted_md, + # Embed YouTube videos + converted_md = markdown2.markdown(wiki_page.content.replace("<", "<"), + extras=["spoiler", "tables", "smarty-pants", "fenced-code-blocks"]) + converted_md = re.sub(r"{https?:\/\/(?:www\.)?(?:youtube\.com\/watch\?.*?&?v=|youtu.be\/)([0-9A-Za-z-]+).*?}", + r'
' + r' ' + r'
', converted_md) + return render_template("wiki.html", key=key, wiki_page=wiki_page, converted_md=Markup(converted_md), wiki_log=wiki_latest_edit, config=config) elif request.method == "POST": user_id = fl_session.get('user_id')