Show
Ignore:
Timestamp:
03/25/08 09:24:47 (8 months ago)
Author:
JensDiemer
Message:

move the automatic headline anchor function from tinyTextile markup ( changeset:1500 ) into a middleware. So every markups becomes headline anchors. See also: ticket:46

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid/PyLucid/tools/shortcuts.py

    r1331 r1503  
    1111    $Author$ 
    1212 
    13     :copyright: 2007 by Jens Diemer. 
     13    :copyleft: 2007-2008 by Jens Diemer. 
    1414    :license: GNU GPL v3, see LICENSE.txt for more details. 
    1515""" 
    1616 
    1717import string 
     18 
    1819ALLOW_CHARS = string.ascii_letters + string.digits + "_" 
     20 
    1921 
    2022def makeUnique(item_name, name_list): 
    2123    """ 
    22     returns a unique shortcut. 
     24    returns a URL safe, unique shortcut. 
    2325    - delete all non-ALLOW_CHARS characters. 
    2426    - if the shotcut already exists in name_list -> add a sequential number 
    2527    Note: 
    26     Not only used for making page shortcuts unique. 
    27     Also used in PyLucid.defaulttags.lucidTag.lucidTagNode._add_unique_div() 
     28    Not only used for making page shortcuts unique with getUniqueShortcut(), 
     29    also used in: 
     30        -PyLucid.defaulttags.lucidTag.lucidTagNode._add_unique_div() 
     31        -PyLucid.middlewares.headline_anchor.HeadlineAnchor() 
    2832    """ 
    2933    # delete all non-ALLOW_CHARS characters and separate in parts 
     
    3236        if not char in ALLOW_CHARS: 
    3337            if parts[-1] != "": 
    34                 # No double "-" e.g.: "foo - bar" -> "foo-bar" not "foo---bar"    
     38                # No double "-" e.g.: "foo - bar" -> "foo-bar" not "foo---bar" 
    3539                parts.append("") 
    3640        else: 
     
    5660    return item_name 
    5761 
     62 
    5863def getUniqueShortcut(shortcut, exclude_shortcut=None): 
    5964    from PyLucid.models import Page 
     
    6772#    print "existing_shortcuts:", existing_shortcuts 
    6873    return makeUnique(shortcut, existing_shortcuts) 
     74 
    6975 
    7076