- Author:
- chuck-harmston
- Posted:
- August 26, 2009
- Language:
- Python
- Version:
- 1.1
- Score:
- 2 (after 2 ratings)
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" }}
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
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Cheers, I love djangosnippets!
#
Please login first before commenting.