diff --git a/docs/release-notes/version-3.0.md b/docs/release-notes/version-3.0.md index fcebdb4d7..a8a074d3f 100644 --- a/docs/release-notes/version-3.0.md +++ b/docs/release-notes/version-3.0.md @@ -6,6 +6,7 @@ * [#2101](https://github.com/netbox-community/netbox/issues/2101) - Add missing `q` filters for necessary models * [#7424](https://github.com/netbox-community/netbox/issues/7424) - Add virtual chassis filters for device components +* [#7531](https://github.com/netbox-community/netbox/issues/7531) - Add Markdown support for strikethrough formatting * [#7542](https://github.com/netbox-community/netbox/issues/7542) - Add optional VLAN group column to prefixes table * [#7803](https://github.com/netbox-community/netbox/issues/7803) - Improve live reloading of custom scripts * [#7810](https://github.com/netbox-community/netbox/issues/7810) - Add IEEE 802.15.1 interface type diff --git a/netbox/utilities/markdown.py b/netbox/utilities/markdown.py new file mode 100644 index 000000000..00b6330f1 --- /dev/null +++ b/netbox/utilities/markdown.py @@ -0,0 +1,16 @@ +import markdown +from markdown.inlinepatterns import SimpleTagPattern + +STRIKE_RE = r'(~{2})(.+?)(~{2})' + + +class StrikethroughExtension(markdown.Extension): + """ + A python-markdown extension which support strikethrough formatting (e.g. "~~text~~"). + """ + def extendMarkdown(self, md): + md.inlinePatterns.register( + markdown.inlinepatterns.SimpleTagPattern(STRIKE_RE, 'del'), + 'strikethrough', + 200 + ) diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py index b047bb698..0f3f75bc2 100644 --- a/netbox/utilities/templatetags/helpers.py +++ b/netbox/utilities/templatetags/helpers.py @@ -15,6 +15,7 @@ from django.utils.safestring import mark_safe from markdown import markdown from utilities.forms import get_selected_values, TableConfigForm +from utilities.markdown import StrikethroughExtension from utilities.utils import foreground_color register = template.Library() @@ -54,7 +55,7 @@ def render_markdown(value): value = re.sub(pattern, '[\\1]: \\3', value, flags=re.IGNORECASE) # Render Markdown - html = markdown(value, extensions=['fenced_code', 'tables']) + html = markdown(value, extensions=['fenced_code', 'tables', StrikethroughExtension()]) return mark_safe(html)