mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 08:25:17 -06:00
Allow render_markdown to have custom css classes
(cherry picked from commit 3e852acc8e
)
This commit is contained in:
parent
16e2283d19
commit
a195dfc8dc
@ -35,6 +35,7 @@ register = template.Library()
|
|||||||
# General
|
# General
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
@register.filter()
|
@register.filter()
|
||||||
def linkify(instance, attr=None):
|
def linkify(instance, attr=None):
|
||||||
"""
|
"""
|
||||||
@ -129,6 +130,7 @@ def tzoffset(value):
|
|||||||
# Content types
|
# Content types
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
@register.filter()
|
@register.filter()
|
||||||
def content_type(model):
|
def content_type(model):
|
||||||
"""
|
"""
|
||||||
@ -152,22 +154,30 @@ def content_type_id(model):
|
|||||||
# Rendering
|
# Rendering
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
@register.filter('markdown', is_safe=True)
|
@register.filter('markdown', is_safe=True)
|
||||||
def render_markdown(value):
|
def render_markdown(value, classes=""):
|
||||||
"""
|
"""
|
||||||
Render a string as Markdown. This filter is invoked as "markdown":
|
Render a string as Markdown. This filter is invoked as "markdown":
|
||||||
|
Args: optional coma separated list of classes to add to the generated div
|
||||||
|
(stripped of leading and trailing whitespace)
|
||||||
|
|
||||||
|
{{ md_source_text|markdown:"classa, classb,classc, classd " }}
|
||||||
|
|
||||||
{{ md_source_text|markdown }}
|
|
||||||
"""
|
"""
|
||||||
if not value:
|
if not value:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
if classes:
|
||||||
|
# Remove any leading or trailing whitespace from each class name
|
||||||
|
classes = ", ".join(map(str.strip, classes.split(',')))
|
||||||
|
|
||||||
# Render Markdown
|
# Render Markdown
|
||||||
html = markdown(value, extensions=['def_list', 'fenced_code', 'tables', StrikethroughExtension()])
|
html = markdown(value, extensions=['def_list', 'fenced_code', 'tables', StrikethroughExtension()])
|
||||||
|
|
||||||
# If the string is not empty wrap it in rendered-markdown to style tables
|
# If the string is not empty wrap it in rendered-markdown to style tables
|
||||||
if html:
|
if html:
|
||||||
html = f'<div class="rendered-markdown">{html}</div>'
|
html = f'<div class="rendered-markdown{" "+classes if classes else ""}">{html}</div>'
|
||||||
|
|
||||||
schemes = get_config().ALLOWED_URL_SCHEMES
|
schemes = get_config().ALLOWED_URL_SCHEMES
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user