summaryrefslogtreecommitdiffstats
path: root/askbot/conf/markup.py
blob: 75a612e4fbdd16d496911c5645e9a5dd57001d99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
"""
Settings that modify processing of user text input
"""

from askbot.conf.settings_wrapper import settings
from askbot.conf.super_groups import DATA_AND_FORMATTING
from askbot.deps.livesettings import ConfigurationGroup
from askbot.deps.livesettings import BooleanValue, StringValue, LongStringValue
from askbot import const
from django.utils.translation import ugettext_lazy as _
import re

MARKUP = ConfigurationGroup(
                    'MARKUP',
                    _('Markup in posts'),
                    super_group = DATA_AND_FORMATTING
                )

def regex_settings_validation(*args):
    """
    Validate the regular expressions
    """
    try:

        new_value = args[1]
        regex_list = new_value.split('\n')
        
        for i in range(0, len(regex_list)):
            re.compile(regex_list[i].strip())
        return args[1]
    
    except Exception:
        # The regex is invalid, so we overwrite it with empty string
        return ""


settings.register(
    BooleanValue(
        MARKUP,
        'MARKUP_CODE_FRIENDLY',
        description = _('Enable code-friendly Markdown'),
        help_text = _(
            'If checked, underscore characters will not '
            'trigger italic or bold formatting - '
            'bold and italic text can still be marked up '
            'with asterisks. Note that "MathJax support" '
            'implicitly turns this feature on, because '
            'underscores are heavily used in LaTeX input.'
        ),
        default = False
    )
)

settings.register(
    BooleanValue(
        MARKUP,
        'ENABLE_MATHJAX',
        description=_('Mathjax support (rendering of LaTeX)'),
        help_text=_(
                    'If you enable this feature, '
                    '<a href="%(url)s">mathjax</a> must be '
                    'installed on your server in its own directory.'
                    ) % {
                            'url': const.DEPENDENCY_URLS['mathjax'],
                        },
        default = False
    )
)

settings.register(
    StringValue(
        MARKUP,
        'MATHJAX_BASE_URL',
        description=_('Base url of MathJax deployment'),
        help_text=_(
                    'Note - <strong>MathJax is not included with '
                    'askbot</strong> - you should deploy it yourself, '
                    'preferably at a separate domain and enter url '
                    'pointing to the "mathjax" directory '
                    '(for example: http://mysite.com/mathjax)'
                    ),
        default = ''
    )
)


settings.register(
    BooleanValue(
        MARKUP,
        'ENABLE_AUTO_LINKING',
        description=_('Enable autolinking with specific patterns'),
        help_text=_(
            'If you enable this feature, '
            'the application  will be able to '
            'detect patterns and auto link to URLs'        
        ),
        default = False
    )
)


settings.register(
    LongStringValue(
        MARKUP,
        'AUTO_LINK_PATTERNS',
        description=_('Regexes to detect the link patterns'),
        help_text=_(
            'Enter valid regular expressions for the patters,'
            ' one per line.'
            ' For example to'
            ' detect a bug pattern like #bug123,'
            ' use the following regex: #bug(\d+). The numbers'
            ' captured by the pattern in the parentheses will'
            ' be transferred to the link url template.'
            ' Please look up more information about regular'
            ' expressions elsewhere.'
        ),
        update_callback=regex_settings_validation,
        default = ''
        )
    )

settings.register(
    LongStringValue(
        MARKUP,
        'AUTO_LINK_URLS',
        description=_('URLs for autolinking'),
        help_text=_(
            'Here, please enter url templates for the patterns'
            ' entered in the previous setting, also one entry per line.'
            ' <strong>Make sure that number of lines in this setting'
            ' and the previous one are the same</strong>'
            ' For example template'
            ' https://bugzilla.redhat.com/show_bug.cgi?id=\\1'
            ' together with the pattern shown above'
            ' and the entry in the post #123'
            ' will produce link to the bug 123 in the redhat bug tracker.'
        ),
        default = ''
    )
)