|
30 | 30 |
|
31 | 31 | DEFAULT_MARKUP_TYPE = getattr(settings, 'DEFAULT_MARKUP_TYPE', 'restructuredtext')
|
32 | 32 |
|
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 |
| - |
38 | 33 | PAGE_PATH_RE = re.compile(r"""
|
39 | 34 | ^
|
40 | 35 | /? # We can optionally start with a /
|
|
65 | 60 | 'Markdown'
|
66 | 61 | )
|
67 | 62 |
|
| 63 | +# Add our own Github style Markdown parser, which doesn't apply the default |
| 64 | +# tagfilter used by Github (we can be more liberal, since we know our page |
| 65 | +# editors). |
| 66 | + |
| 67 | +def unsafe_markdown_to_html(text, options=0): |
| 68 | + |
| 69 | + """Render the given GitHub-flavored Makrdown to HTML. |
| 70 | +
|
| 71 | + This function is similar to cmarkgfm.github_flavored_markdown_to_html(), |
| 72 | + except that it allows raw HTML to get rendered, which is useful when |
| 73 | + using jQuery UI script extensions on pages. |
| 74 | +
|
| 75 | + """ |
| 76 | + # Set options for cmarkgfm for "unsafe" renderer, see |
| 77 | + # https://github.com/theacodes/cmarkgfm#advanced-usage |
| 78 | + options = options | ( |
| 79 | + cmarkgfmOptions.CMARK_OPT_UNSAFE | |
| 80 | + cmarkgfmOptions.CMARK_OPT_GITHUB_PRE_LANG |
| 81 | + ) |
| 82 | + return cmarkgfm.markdown_to_html_with_extensions( |
| 83 | + text, options=options, |
| 84 | + extensions=[ |
| 85 | + 'table', 'autolink', 'strikethrough', 'tasklist' |
| 86 | + ]) |
| 87 | + |
68 | 88 | RENDERERS.append(
|
69 | 89 | (
|
70 | 90 | "markdown_unsafe",
|
71 |
| - lambda markdown_text: cmarkgfm.github_flavored_markdown_to_html(markdown_text, options=CMARKGFM_UNSAFE_OPTIONS), |
| 91 | + unsafe_markdown_to_html, |
72 | 92 | "Markdown (unsafe)",
|
73 | 93 | )
|
74 | 94 | )
|
|
0 commit comments