Table of Contents

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

  1. Django profiler by dogada 5 years, 7 months ago
  2. Mathematical Captcha by dogada 5 years, 6 months ago
  3. Test IP against IP address+Subnet whitelist by mtigas 3 years, 11 months ago
  4. Template tag: split list to n sublists by movielady 4 years, 11 months ago
  5. Truncate HTML without breaking tags by olau 4 years, 1 month ago

Comments

(Forgotten your password?)