Closes #7531: Add Markdown support for strikethrough formatting

This commit is contained in:
jeremystretch 2021-11-17 16:50:23 -05:00
parent 23d90823a3
commit 6a369ac985
3 changed files with 19 additions and 1 deletions

View File

@ -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

View File

@ -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
)

View File

@ -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)