Re-add the rst filter that got removed
This is still used
@@ -53,6 +53,44 @@ def make_document_url(project, version=None, page='', path=''):
return resolve(project=project, version_slug=version, filename=filename)
+@register.filter(is_safe=True)
+def restructuredtext(value, short=False):
+ try:
+ from docutils.core import publish_parts
+ from docutils import ApplicationError
+ except ImportError:
+ if settings.DEBUG:
+ raise template.TemplateSyntaxError(
+ "Error in 'restructuredtext' filter: "
+ "The Python docutils library isn't installed.",
+ )
+ return force_text(value)
+ else:
+ docutils_settings = {
+ 'raw_enabled': False,
+ 'file_insertion_enabled': False,
+ }
+ docutils_settings.update(
+ settings.RESTRUCTUREDTEXT_FILTER_SETTINGS,
+ )
+ try:
+ parts = publish_parts(
+ source=force_bytes(value),
+ writer_name='html4css1',
+ settings_overrides=docutils_settings,
+ )
+ except ApplicationError:
+ return force_text(value)
+
+ out = force_text(parts['fragment'])
+ try:
+ if short:
+ out = out.split('\n')[0]
+ except IndexError:
+ pass
+ return mark_safe(out)
+
+
@register.filter
def get_project(slug):
try:
