Changeset 1503

Show
Ignore:
Timestamp:
25.03.2008 09:24:47 (2 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:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/pylucid/PyLucid/middlewares/pagestats.py

    r1481 r1503  
    6767 
    6868        # Put only the statistic into HTML pages 
    69         if response._headers.get('content-type', None) == "text/html"
     69        if not "html" in response._headers["content-type"][1]
    7070            # No HTML Page -> do nothing 
    7171            return response 
  • trunk/pylucid/PyLucid/middlewares/page_cache_debug.py

    r1168 r1503  
    5353 
    5454        content = response.content 
    55         if "html" in response.headers['Content-Type']: 
     55        if "html" in response._headers["content-type"][1]: 
    5656            # Try to insert the info into a html valid way. 
    5757            old_content = content 
  • trunk/pylucid/PyLucid/settings_example.py

    r1499 r1503  
    105105    'django.middleware.doc.XViewMiddleware', 
    106106 
     107    # Add a human readable anchor to every html headline: 
     108    'PyLucid.middlewares.headline_anchor.HeadlineAnchor', 
     109 
     110    # Insert a statistic line into the generated page: 
    107111    'PyLucid.middlewares.pagestats.PageStatsMiddleware', 
    108112) 
  • trunk/pylucid/PyLucid/system/tinyTextile.py

    r1500 r1503  
    2828__version__ = "$Rev$" 
    2929 
    30 import sys, re, string 
     30import sys, re 
    3131 
    3232from PyLucid.tools.utils import escape 
     
    3434 
    3535 
    36 HEADLINE = ( 
    37     '<h%(no)s id="%(anchor)s">' 
    38     '<a title="Link to this section" href="%(link)s#%(anchor)s" class="anchor">' 
    39     '%(txt)s</a>' 
    40     '</h%(no)s>\n' 
    41 ) 
    42  
    43  
    4436class TinyTextileParser: 
    45     def __init__(self, out_obj, permalink, context): 
     37    def __init__(self, out_obj, context): 
    4638        self.out = out_obj 
    47         self.permalink = permalink 
    4839        self.context = context 
    4940        self.page_msg   = context["page_msg"] 
     
    5344            [ # <h1>-Headlines 
    5445                r"\Ah(\d)\. (.+)(?usm)", 
    55                 self.headline 
     46                r"<h\1>\2</h\1>" 
    5647            ], 
    5748        ]) 
     
    165156    def escaping(self, matchobj): 
    166157        return escape(matchobj.group(1)) 
    167  
    168     def headline(self, matchobj): 
    169         """ 
    170         Insert a html headline with a anchor. 
    171         """ 
    172         text = matchobj.group(2) 
    173         anchor = "".join( 
    174             [char for char in text if char in string.ascii_letters] 
    175         ) 
    176         result = HEADLINE % { 
    177             "no": matchobj.group(1), 
    178             "txt": text, 
    179             "link": self.permalink, 
    180             "anchor": anchor, 
    181         } 
    182         return result 
    183158 
    184159    def shortcutLink(self, matchobj): 
  • trunk/pylucid/PyLucid/tools/content_processors.py

    r1500 r1503  
    4646        from PyLucid.system.tinyTextile import TinyTextileParser 
    4747        out_obj = SimpleStringIO() 
    48  
    49         current_page = context["PAGE"] 
    50         permalink = current_page.get_permalink() 
    51  
    52         markup_parser = TinyTextileParser(out_obj, permalink, context) 
     48        markup_parser = TinyTextileParser(out_obj, context) 
    5349        markup_parser.parse(content) 
    5450        content = out_obj.getvalue() 
  • 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 
  • trunk/pylucid/tests/test_tinyTextile.py

    r1500 r1503  
    3535#VERBOSE = 1 
    3636VERBOSE = 2 
    37  
    38 PERMALINK = "/permalink/" 
    3937 
    4038 
     
    113111        self.fake_context = get_fake_context() 
    114112        self.out = SimpleStringIO() 
    115         self.textile = TinyTextileParser(self.out, PERMALINK, self.fake_context) 
     113        self.textile = TinyTextileParser(self.out, self.fake_context) 
    116114 
    117115    def tearDown(self): 
     
    243241        """) 
    244242        out_test = self._prepare_text(""" 
    245             <h1 id="headlineA"><a title="Link to this section" href="/permalink/#headlineA" class="anchor">headline A</a></h1> 
    246              
     243            <h1>headline A</h1> 
    247244            <p>Text1</p> 
    248             <h2 id="headlineB"><a title="Link to this section" href="/permalink/#headlineB" class="anchor">headline B $%#</a></h2> 
    249              
     245            <h2>headline B $%#</h2> 
    250246            <p>Text2</p> 
    251247