from django import forms
from django.forms import fields
from django.db import models
from django.db.models import permalink
from django.conf import settings
import re, datetime
from couchdbkit.ext.django.schema import *
from couchdbkit.ext.django.forms import *
from couchdbkit.exceptions import ResourceNotFound
from django.utils.translation import gettext_lazy as _
MARKUP_LANGUAGE = getattr(settings, 'MARKUP_LANGUAGE', None)
def markup(text, small_headings=False, no_follow=True, escape=False,
scale_headings=True):
"""Markup text using the markup language specified in the settings.
"""
if MARKUP_LANGUAGE == 'markdown':
import markdown
safe_mode = 'escape' if escape else None
try:
import pygments
options = ['codehilite', 'extra', 'toc']
if scale_headings:
options.append('headerid(level=3, forceid=False)')
text = markdown.markdown(text, options, safe_mode=safe_mode)
except ImportError:
options = ['extra', 'toc']
if scale_headings:
options.append('headerid(level=3, forceid=False)')
text = markdown.markdown(text, options, safe_mode=safe_mode)
if small_headings:
text = re.sub('<(/?h)[1-6]', '<\g<1>5', text)
if no_follow:
text = re.sub(']*nofollow)', '