1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | from django.template.defaultfilters import stringfilter
from django import template
register = template.Library()
@register.filter(name='indent')
@stringfilter
def indent(value, arg=1):
"""
Template filter to add the given number of tabs to the beginning of
each line. Useful for keeping markup pretty, plays well with Markdown.
Usage:
{{ content|indent:"2" }}
{{ content|markdown|indent:"2" }}
"""
import re
regex = re.compile("^", re.M)
return re.sub(regex, "\t"*int(arg), value)
|
More like this
- HTML Prettifier by Eloff 5 years, 3 months ago
- extending generic_markup.apply_markup by mandric 5 years, 12 months ago
- render_markup filter, specify the markup filter as a string by exogen 6 years, 1 month ago
- Tags & filters for rendering search results by exogen 5 years, 1 month ago
- Skip only specified spaces by axil 1 year, 3 months ago
Comments
Cheers, I love djangosnippets!
#