1 2 3 4 5 6 7 8 9 | @register.filter
def toc(text):
"""Extract IDs from text and return Table of Contents,
as list of tuples (id, name)."""
items = []
for i in re.finditer(r'<[^>]*?id="(?P<id>[^"]*?)".*?>', text):
_id = i.group('id')
items.append({'id':_id, 'name': _id.replace('_', ' ').strip()})
return items
|
More like this
- Django profiler by dogada 5 years, 7 months ago
- Mathematical Captcha by dogada 5 years, 6 months ago
- Test IP against IP address+Subnet whitelist by mtigas 3 years, 11 months ago
- Template tag: split list to n sublists by movielady 4 years, 11 months ago
- Truncate HTML without breaking tags by olau 4 years, 1 month ago
Comments