Skip to content

Commit cfdaf1a

Browse files
authored
configure cmarkgfm to make cms pages more flexible (#2182)
* configure cmarkgfm to make cms pages more flexible closes #2181 * move unsafe markdown to its own render selection
1 parent 8b118b5 commit cfdaf1a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pages/models.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from markupfield.markup import DEFAULT_MARKUP_TYPES
2222

2323
import cmarkgfm
24+
from cmarkgfm.cmark import Options as cmarkgfmOptions
2425

2526
from cms.models import ContentManageable
2627
from fastly.utils import purge_url
@@ -29,6 +30,11 @@
2930

3031
DEFAULT_MARKUP_TYPE = getattr(settings, 'DEFAULT_MARKUP_TYPE', 'restructuredtext')
3132

33+
# Set options for cmarkgfm for "unsafe" renderer, see https://github.com/theacodes/cmarkgfm#advanced-usage
34+
CMARKGFM_UNSAFE_OPTIONS = (
35+
cmarkgfmOptions.CMARK_OPT_UNSAFE
36+
)
37+
3238
PAGE_PATH_RE = re.compile(r"""
3339
^
3440
/? # We can optionally start with a /
@@ -59,6 +65,14 @@
5965
'Markdown'
6066
)
6167

68+
RENDERERS.append(
69+
(
70+
"markdown_unsafe",
71+
lambda markdown_text: cmarkgfm.github_flavored_markdown_to_html(markdown_text, options=CMARKGFM_UNSAFE_OPTIONS),
72+
"Markdown (unsafe)",
73+
)
74+
)
75+
6276

6377
class Page(ContentManageable):
6478
title = models.CharField(max_length=500)

0 commit comments

Comments
 (0)