From 42c4bdddefd44523e1005a621a21871f6337bedd Mon Sep 17 00:00:00 2001 From: Brian Tiemann Date: Wed, 21 Aug 2024 17:50:09 -0400 Subject: [PATCH] Add clamp_height to the markdown filter which limits max height to 200 (scrollable) on the container div --- netbox/project-static/dist/netbox.css | Bin 543336 -> 543409 bytes .../styles/custom/_markdown.scss | 5 +++++ .../templates/builtins/customfield_value.html | 2 +- .../templatetags/builtins/filters.py | 13 +++++++++++-- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/netbox/project-static/dist/netbox.css b/netbox/project-static/dist/netbox.css index 80d23acfa6878f2ea8c5b86d928f6369cb5131b1..dcc103d85d3afb9a3c05594081549e11a2f6f51a 100644 GIT binary patch delta 104 zcmaDcMRDU)#fBEf7N!>F7M2#)7Pc1lEga`PJW5jR^ommRQc{ajQ*?6^i?UPl%k%Wg zQj1D5lM{1vi<67;b8@P46DxExQZv&tO00|w3<@f&^MNYTa`MY{E3F_(wx9Fhn8gSH D0Np2I delta 31 ncmdluRq@3X#fBEf7N!>F7M2#)7Pc1lEga`Pwo7<&%wz-ry(9|C diff --git a/netbox/project-static/styles/custom/_markdown.scss b/netbox/project-static/styles/custom/_markdown.scss index cb4527f37..fb9182a19 100644 --- a/netbox/project-static/styles/custom/_markdown.scss +++ b/netbox/project-static/styles/custom/_markdown.scss @@ -35,6 +35,11 @@ td > .rendered-markdown { } } +td > .rendered-markdown.vertical-scroll { + max-height: 200px; + overflow-y: scroll; +} + // Markdown preview .markdown-widget { .preview { diff --git a/netbox/utilities/templates/builtins/customfield_value.html b/netbox/utilities/templates/builtins/customfield_value.html index dbf10e1bf..7fe8d1eff 100644 --- a/netbox/utilities/templates/builtins/customfield_value.html +++ b/netbox/utilities/templates/builtins/customfield_value.html @@ -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 %} diff --git a/netbox/utilities/templatetags/builtins/filters.py b/netbox/utilities/templatetags/builtins/filters.py index 738b9a23e..03c91b132 100644 --- a/netbox/utilities/templatetags/builtins/filters.py +++ b/netbox/utilities/templatetags/builtins/filters.py @@ -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'
{html}
' + classes = ['rendered-markdown'] + if clamp_height: + classes.append('vertical-scroll') + classes_str = ' '.join(classes) + html = f'
{html}
' schemes = get_config().ALLOWED_URL_SCHEMES