GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

MarkdownRenderer.render()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
c 6
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 1
1
import bleach
2
3
from django.utils.safestring import mark_safe
4
5
from markdown import markdown
6
7
from simple_forums.backends.renderers import BaseRenderer
8
from simple_forums.utils import get_setting
9
10
11
class MarkdownRenderer(BaseRenderer):
12
    """ Handles rendering markdown into html """
13
14
    DEFAULT_EXTENSIONS = [
15
        'pymdownx.github',
16
    ]
17
18
    # Attributes and tags used for rendering markdown taken from:
19
    # https://github.com/yourcelf/bleach-whitelist
20
    #
21
    # Slightly modified
22
23
    MARKDOWN_ATTRS = {
24
        'a': ['alt', 'href', 'title'],
25
        'img': ['alt', 'src', 'title'],
26
    }
27
28
    MARKDOWN_TAGS = {
29
        'a',
30
        'b', 'blockquote', 'br',
31
        'code',
32
        'dd', 'div', 'dt',
33
        'em',
34
        'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr',
35
        'i', 'img',
36
        'li',
37
        'ol',
38
        'p',
39
        'span', 'strong',
40
        'tt',
41
        'ul',
42
    }
43
44
    @staticmethod
45
    def get_extensions():
46
        """ Get a list of extensions to use """
47
        return get_setting(
48
            'markdown_extensions',
49
            MarkdownRenderer.DEFAULT_EXTENSIONS)
50
51
    def render(self, text):
52
        """ Convert the given text into html """
53
        converted = markdown(
54
            text,
55
            extensions=MarkdownRenderer.get_extensions(),
56
            output_format='html5')
57
58
        cleaned = bleach.clean(
59
            converted,
60
            attributes=self.MARKDOWN_ATTRS,
61
            tags=self.MARKDOWN_TAGS)
62
63
        return mark_safe(cleaned)
64