Skip to content

Commit 6a369ac

Browse files
committed
Closes #7531: Add Markdown support for strikethrough formatting
1 parent 23d9082 commit 6a369ac

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

docs/release-notes/version-3.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
* [#2101](https://github.com/netbox-community/netbox/issues/2101) - Add missing `q` filters for necessary models
88
* [#7424](https://github.com/netbox-community/netbox/issues/7424) - Add virtual chassis filters for device components
9+
* [#7531](https://github.com/netbox-community/netbox/issues/7531) - Add Markdown support for strikethrough formatting
910
* [#7542](https://github.com/netbox-community/netbox/issues/7542) - Add optional VLAN group column to prefixes table
1011
* [#7803](https://github.com/netbox-community/netbox/issues/7803) - Improve live reloading of custom scripts
1112
* [#7810](https://github.com/netbox-community/netbox/issues/7810) - Add IEEE 802.15.1 interface type

netbox/utilities/markdown.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import markdown
2+
from markdown.inlinepatterns import SimpleTagPattern
3+
4+
STRIKE_RE = r'(~{2})(.+?)(~{2})'
5+
6+
7+
class StrikethroughExtension(markdown.Extension):
8+
"""
9+
A python-markdown extension which support strikethrough formatting (e.g. "~~text~~").
10+
"""
11+
def extendMarkdown(self, md):
12+
md.inlinePatterns.register(
13+
markdown.inlinepatterns.SimpleTagPattern(STRIKE_RE, 'del'),
14+
'strikethrough',
15+
200
16+
)

netbox/utilities/templatetags/helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from markdown import markdown
1616

1717
from utilities.forms import get_selected_values, TableConfigForm
18+
from utilities.markdown import StrikethroughExtension
1819
from utilities.utils import foreground_color
1920

2021
register = template.Library()
@@ -54,7 +55,7 @@ def render_markdown(value):
5455
value = re.sub(pattern, '[\\1]: \\3', value, flags=re.IGNORECASE)
5556

5657
# Render Markdown
57-
html = markdown(value, extensions=['fenced_code', 'tables'])
58+
html = markdown(value, extensions=['fenced_code', 'tables', StrikethroughExtension()])
5859

5960
return mark_safe(html)
6061

0 commit comments

Comments
 (0)