Login

Table of Contents

Author:
dogada
Posted:
November 24, 2007
Language:
Python
Version:
.96
Score:
-1 (after 1 ratings)

Simple template filter that extracts from a text ids, replaces '_' with spaces and produces hyperlinked Table of Contents.

More info and usage example please see at http://www.mysoftparade.com/blog/autogenerated-toc/

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. Stuff by NixonDash 1 month ago
  2. Add custom fields to the built-in Group model by jmoppel 3 months, 1 week ago
  3. Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 6 months, 3 weeks ago
  4. Python Django CRUD Example Tutorial by tuts_station 7 months ago
  5. Browser-native date input field by kytta 8 months, 3 weeks ago

Comments

Please login first before commenting.