Changeset 1500
- Timestamp:
- 03/24/08 12:48:32 (8 months ago)
- Location:
- trunk/pylucid
- Files:
-
- 4 modified
-
PyLucid/system/tinyTextile.py (modified) (3 diffs)
-
PyLucid/tools/content_processors.py (modified) (1 diff)
-
tests/test_tinyTextile.py (modified) (6 diffs)
-
tests/__init__.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid/PyLucid/system/tinyTextile.py
r1327 r1500 28 28 __version__ = "$Rev$" 29 29 30 import sys, re 30 import sys, re, string 31 31 32 from PyLucid.tools.utils import escape 32 33 from PyLucid.system.response import SimpleStringIO 33 34 34 35 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 35 44 class TinyTextileParser: 36 def __init__(self, out_obj, context):45 def __init__(self, out_obj, permalink, context): 37 46 self.out = out_obj 47 self.permalink = permalink 38 48 self.context = context 39 49 self.page_msg = context["page_msg"] 40 50 41 # Regeln für Blockelemente51 # Blockelements 42 52 self.block_rules = self._compile_rules([ 43 [ # <h1>- Überschriften44 r"\Ah(\d)\. +(.*)(?us)",45 r"<h\1>\2</h\1>"53 [ # <h1>-Headlines 54 r"\Ah(\d)\. (.+)(?usm)", 55 self.headline 46 56 ], 47 57 ]) 48 58 49 # Regeln für Inlineelemente59 # Inlineelements 50 60 self.inline_rules = self._compile_rules([ 51 61 [ # HTML-Escaping … … 155 165 def escaping(self, matchobj): 156 166 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 157 183 158 184 def shortcutLink(self, matchobj): … … 422 448 423 449 424 -
trunk/pylucid/PyLucid/tools/content_processors.py
r1464 r1500 46 46 from PyLucid.system.tinyTextile import TinyTextileParser 47 47 out_obj = SimpleStringIO() 48 markup_parser = TinyTextileParser(out_obj, context) 48 49 current_page = context["PAGE"] 50 permalink = current_page.get_permalink() 51 52 markup_parser = TinyTextileParser(out_obj, permalink, context) 49 53 markup_parser.parse(content) 50 54 content = out_obj.getvalue() -
trunk/pylucid/tests/test_tinyTextile.py
r1494 r1500 36 36 VERBOSE = 2 37 37 38 PERMALINK = "/permalink/" 38 39 39 40 … … 112 113 self.fake_context = get_fake_context() 113 114 self.out = SimpleStringIO() 114 self.textile = TinyTextileParser(self.out, self.fake_context)115 self.textile = TinyTextileParser(self.out, PERMALINK, self.fake_context) 115 116 116 117 def tearDown(self): … … 125 126 """ 126 127 txt = txt.splitlines() 127 assert txt[0]=="", "First must be empty!" 128 assert txt[0]=="", "First must be empty!" 128 129 txt = txt[1:] # Skip the first line 129 130 … … 200 201 self.textile.parse(content) 201 202 self.assertEqual(self.out.getvalue(),out_test) 202 203 203 204 def testTextile_text3(self): 204 205 test_text = self._prepare_text(""" … … 233 234 def testTextile_headline1(self): 234 235 content = self._prepare_text(""" 235 h1. h-1 headline 236 237 h2. h-2 headline 238 """) 239 out_test = self._prepare_text(""" 240 <h1>h-1 headline</h1> 241 <h2>h-2 headline</h2> 242 236 h1. headline A 237 238 Text1 239 240 h2. headline B $%# 241 242 Text2 243 """) 244 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 247 <p>Text1</p> 248 <h2 id="headlineB"><a title="Link to this section" href="/permalink/#headlineB" class="anchor">headline B $%#</a></h2> 249 250 <p>Text2</p> 251 243 252 """) 244 253 … … 380 389 self.textile.parse(content) 381 390 self.assertEqual(self.out.getvalue(),out_test) 382 391 383 392 def testTextile_escaping2(self): 384 393 content = self._prepare_text(""" -
trunk/pylucid/tests/__init__.py
r1499 r1500 192 192 HREF_RE = re.compile('<a href="(.+?)".*?>(.+?)</a>') 193 193 194 def assertResponse(self, response, must_contain , must_not_contain=()):194 def assertResponse(self, response, must_contain=(), must_not_contain=()): 195 195 """ 196 196 Check the content of the response
