mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-07 16:18:16 -06:00
Add clamp_height to the markdown filter which limits max height to 200 (scrollable) on the container div
This commit is contained in:
parent
96802b4edb
commit
42c4bdddef
BIN
netbox/project-static/dist/netbox.css
vendored
BIN
netbox/project-static/dist/netbox.css
vendored
Binary file not shown.
@ -35,6 +35,11 @@ td > .rendered-markdown {
|
||||
}
|
||||
}
|
||||
|
||||
td > .rendered-markdown.vertical-scroll {
|
||||
max-height: 200px;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
// Markdown preview
|
||||
.markdown-widget {
|
||||
.preview {
|
||||
|
@ -3,7 +3,7 @@
|
||||
{% if customfield.type == 'integer' and value is not None %}
|
||||
{{ value }}
|
||||
{% elif customfield.type == 'longtext' and value %}
|
||||
{{ value|markdown }}
|
||||
{{ value|markdown:True }}
|
||||
{% elif customfield.type == 'boolean' and value == True %}
|
||||
{% checkmark value true="True" %}
|
||||
{% elif customfield.type == 'boolean' and value == False %}
|
||||
|
@ -159,11 +159,16 @@ def content_type_id(model):
|
||||
#
|
||||
|
||||
@register.filter('markdown', is_safe=True)
|
||||
def render_markdown(value):
|
||||
def render_markdown(value, clamp_height=False):
|
||||
"""
|
||||
Render a string as Markdown. This filter is invoked as "markdown":
|
||||
|
||||
{{ md_source_text|markdown }}
|
||||
|
||||
If clamp_height is True, the "vertical-scroll" class will be added to the container div which sets a max-height
|
||||
and adds a vertical scrollbar:
|
||||
|
||||
{{ md_source_text|markdown:True }}
|
||||
"""
|
||||
if not value:
|
||||
return ''
|
||||
@ -178,7 +183,11 @@ def render_markdown(value):
|
||||
|
||||
# If the string is not empty wrap it in rendered-markdown to style tables
|
||||
if html:
|
||||
html = f'<div class="rendered-markdown">{html}</div>'
|
||||
classes = ['rendered-markdown']
|
||||
if clamp_height:
|
||||
classes.append('vertical-scroll')
|
||||
classes_str = ' '.join(classes)
|
||||
html = f'<div class="{classes_str}">{html}</div>'
|
||||
|
||||
schemes = get_config().ALLOWED_URL_SCHEMES
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user