-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.py
More file actions
33 lines (24 loc) · 877 Bytes
/
utils.py
File metadata and controls
33 lines (24 loc) · 877 Bytes
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
"""
=================
learnpython.utils
=================
Utilities and helpers for Learn Python site.
"""
from docutils.core import publish_parts
from flask import current_app
from jinja2.filters import do_mark_safe
__all__ = ('restructuredtext_filter', )
def restructuredtext_filter(text, mixed=None):
"""
Convert text to HTML using reStructuredText markup.
"""
app = current_app
docutils_settings = app.config.get('RESTRUCTUREDTEXT_FILTER_SETTINGS', {})
result = (mixed
if mixed is not None and isinstance(mixed, basestring)
else 'fragment')
writer_name = app.config.get('RESTRUCTUREDTEXT_WRITER_NAME', 'html4css1')
parts = publish_parts(source=text,
writer_name=writer_name,
settings_overrides=docutils_settings)
return do_mark_safe(parts[result])