Improve HTML Processing + Introduction of Processed File viewer
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
# common/utils/filters.py
|
||||
|
||||
import pytz
|
||||
import markdown
|
||||
from markupsafe import Markup
|
||||
from datetime import datetime
|
||||
from common.utils.nginx_utils import prefixed_url_for as puf
|
||||
|
||||
@@ -43,6 +45,44 @@ def status_color(status_name):
|
||||
return colors.get(status_name, 'secondary')
|
||||
|
||||
|
||||
def render_markdown(text):
|
||||
"""
|
||||
Renders markdown to HTML using Python's markdown library.
|
||||
Includes common extensions for better rendering.
|
||||
"""
|
||||
if not text:
|
||||
return ""
|
||||
|
||||
# Verwijder de triple backticks en markdown label
|
||||
text = clean_markdown(text)
|
||||
|
||||
# Render de markdown met extensies
|
||||
return Markup(markdown.markdown(text, extensions=[
|
||||
'markdown.extensions.fenced_code',
|
||||
'markdown.extensions.codehilite',
|
||||
'markdown.extensions.tables',
|
||||
'markdown.extensions.toc'
|
||||
]))
|
||||
|
||||
|
||||
def clean_markdown(text):
|
||||
"""
|
||||
Verwijdert triple backticks en markdown aanduiding uit de tekst
|
||||
"""
|
||||
if not text:
|
||||
return ""
|
||||
|
||||
text = text.strip()
|
||||
if text.startswith("```markdown"):
|
||||
text = text[len("```markdown"):].strip()
|
||||
elif text.startswith("```"):
|
||||
text = text[3:].strip()
|
||||
if text.endswith("```"):
|
||||
text = text[:-3].strip()
|
||||
|
||||
return text
|
||||
|
||||
|
||||
def prefixed_url_for(endpoint):
|
||||
return puf(endpoint)
|
||||
|
||||
@@ -55,5 +95,7 @@ def register_filters(app):
|
||||
app.jinja_env.filters['time_difference'] = time_difference
|
||||
app.jinja_env.filters['status_color'] = status_color
|
||||
app.jinja_env.filters['prefixed_url_for'] = prefixed_url_for
|
||||
app.jinja_env.filters['markdown'] = render_markdown
|
||||
app.jinja_env.filters['clean_markdown'] = clean_markdown
|
||||
|
||||
app.jinja_env.globals['prefixed_url_for'] = prefixed_url_for
|
||||
|
||||
Reference in New Issue
Block a user