Changeset 1771
- Timestamp:
- 09/22/08 15:40:45 (9 months ago)
- Location:
- trunk/pylucid_project
- Files:
-
- 2 added
- 5 modified
-
media/PyLucid/internal_page/page_admin/markup_help_creole.html (modified) (2 diffs)
-
PyLucid/system/markups/creole.py (modified) (25 diffs)
-
PyLucid/system/markups/creole2html.py (modified) (8 diffs)
-
PyLucid/system/markups/macros (added)
-
PyLucid/system/markups/macros/__init__.py (added)
-
tests/markup_creole.py (modified) (6 diffs)
-
tests/utils/unittest_addons.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid_project/media/PyLucid/internal_page/page_admin/markup_help_creole.html
r1769 r1771 15 15 <hr /> 16 16 17 <p>Changes to the original creole specs:<br /> 17 <h3>Creole Additions/Macros</h3> 18 <ul> 19 <li><b>source code:</b><br /> 20 You can insert sourcecode: 21 Use <strong><tt><<code ext=<i>.EXT</i>>>...<</code>></tt></strong> 22 and PyLucid used Pygments (if available) to highlight it.<br /> 23 '<strong>.EXT</strong>' is the typical <a href="http://pygments.pocoo.org/docs/lexers/">fileextension/alias</a> of the code. 24 </p> 25 <p>example:</p> 26 <pre> 27 <<code ext=.css>> 28 /* CSS Stylesheet */ 29 .xs {font-family:verdana,arial,helvetica,sans-serif;font-size: x-small} 30 .m {font-size: medium} 31 <</code>> 32 </pre> 33 </li> 34 <li><b>html code:</b><br /> 35 You can insert html code. But it will only pass-through without extra 36 decoration if all lines starts and ends with a normal html tag! Otherwise the code would be escaped.<br /> 37 There exist also a macro to pass everything throught: <strong><tt><<html>>...<</html>></tt></strong> 38 </li> 39 </ul> 40 41 <h3>Changes to the original creole specs:</h3> 18 42 <ul> 19 43 <li><b>image tag:</b><br /> … … 32 56 (every \n would be convertet into <br />) 33 57 </li> 34 <li><b>html code:</b><br />35 You can insert html code. But every line must start with < and end with ><br />36 If the line starts or ends with a other character, the complete line would37 be interpreted as text, so every html characters would be escaped.38 </li>39 58 <li><b>django tags/blocktags:</b><br /> 40 59 You can insert django tags and blocktags. No extra decoration is not needed. -
trunk/pylucid_project/PyLucid/system/markups/creole.py
r1769 r1771 77 77 #-------------------------------------------------------------------------- 78 78 79 macro_block = r'''(?P<macro_block> 80 \s* << (?P<macro_block_start>\w+) \s* (?P<macro_block_args>.*?) >> 81 (?P<macro_block_text>(.|\n)+?) 82 <</(?P=macro_block_start)>> \s* 83 )''' 84 79 85 macro = r'''(?P<macro> 80 86 << 81 (?P<macro_name> \w+) 82 (\( (?P<macro_args> .*?) \))? \s* 83 ([|] \s* (?P<macro_text> .+?) \s* )? 87 (?P<macro_name> \w+) (?P<macro_args>.*?) 84 88 >> 85 89 )''' … … 95 99 # For the block elements: 96 100 separator = r'(?P<separator> ^ \s* ---- \s* $ )' # horizontal line 97 line = r' (?P<line> ^ \s* $ )' # empty line that separates paragraphs101 line = r'''(?P<line> ^\s*$ )''' # empty line that separates paragraphs 98 102 head = r'''(?P<head> 99 103 ^ 100 104 (?P<head_head>=+) \s* 101 105 (?P<head_text> .*? ) 102 =* \s*$103 ) \n*'''106 =*$ 107 )''' 104 108 text = r'(?P<text> .+ ) (?P<break> (?<!\\)$\n(?!\s*$) )?' 105 109 list = r'''(?P<list> … … 124 128 pre_escape = r' ^(?P<indent>\s*) ~ (?P<rest> \}\}\} \s*) $' 125 129 126 # Pass-through all django template blocktags 127 passthrough_block = r'''^ \s*(?P<passthrough_block> 128 {%.*?%} 129 (.|\n)+? 130 {%.*?%} 131 ) \s*$ 132 ''' 133 passthrough_line = r'''(?P<passthrough_line> 130 # Pass-through all django template blocktags 131 pass_block = r'''(?P<pass_block> 132 {% \s* (?P<pass_block_start>.+?) \s* (?P<pass_block_args>.*?) \s* %} 133 (\n|.)*? 134 {% \s* end(?P=pass_block_start) \s* %} 135 )''' 136 137 pass_line = r'''\n(?P<pass_line> 138 (\n|\s)* 134 139 ({%.*?%})| 135 140 ({{.*?}}) 136 )''' 141 (\n|\s)* 142 )''' 143 pass_inline = r'''(?P<pass_inline> 144 ({%.*?%})| 145 ({{.*?}}) 146 )''' 147 137 148 #Pass-through html code lines 138 149 html = r'''(?P<html> 139 ^ \s*<.*?> \s*$150 ^[ \t]*<[a-zA-Z].*?<(/[a-zA-Z ]+?)>[ \t]*$ 140 151 )''' 141 152 … … 153 164 ) \s* 154 165 ''' % '|'.join([link, macro, image, code]) 155 166 156 167 #-------------------------------------------------------------------------- 157 blockelements = (158 "head", "list", "pre", "code", "table", "separator", "macro",159 "passthrough_block", "html"160 )168 # blockelements = ( 169 # "head", "list", "pre", "code", "table", "separator", "macro", 170 # "pass_block", "pass_line", "html" 171 # ) 161 172 162 173 class Parser: … … 177 188 block_re = re.compile( 178 189 '|'.join([ 179 Rules.passthrough_block, 190 Rules.pass_block, 191 Rules.pass_line, 192 Rules.macro_block, 180 193 Rules.html, 181 194 Rules.line, Rules.head, Rules.separator, Rules.pre, Rules.list, … … 189 202 Rules.link, Rules.url, Rules.macro, 190 203 Rules.code, Rules.image, 191 Rules.pass through_line,204 Rules.pass_inline, 192 205 Rules.strong, Rules.emph, Rules.linebreak, 193 206 Rules.escape, Rules.char … … 201 214 self.cur = self.root # The most recent document node 202 215 self.text = None # The node to add inline characters to 216 self.last_text_break = None # Last break node, inserted by _text_repl() 203 217 204 218 #-------------------------------------------------------------------------- 219 220 def cleanup_break(self, old_cur): 221 """ 222 remove unused end line breaks. 223 Should be called before a new block element. 224 e.g.: 225 <p>line one<br /> 226 line two<br /> <--- remove this br-tag 227 </p> 228 """ 229 if self.cur.children: 230 last_child = self.cur.children[-1] 231 if last_child.kind == "break": 232 del(self.cur.children[-1]) 205 233 206 234 def _upto(self, node, kinds): … … 210 238 Start at the node node. 211 239 """ 240 self.cleanup_break(node) # remove unused end line breaks. 212 241 while node.parent is not None and not node.kind in kinds: 213 242 node = node.parent 243 214 244 return node 215 245 … … 221 251 # same method needs several names, because of group names in regexps. 222 252 223 def _pass through_block_repl(self, groups):224 """ Pass-through all django template blocktags """ 253 def _pass_block_repl(self, groups): 254 """ Pass-through all django template blocktags """ 225 255 self._upto_block() 226 DocNode("passthrough_block", self.root, groups["passthrough_block"]) 256 self.cur = self.root 257 DocNode("pass_block", self.cur, groups["pass_block"]) 258 self.text = None 259 _pass_block_start_repl = _pass_block_repl 260 _pass_block_end_repl = _pass_block_repl 261 262 def _pass_line_repl(self, groups): 263 """ Pass-through all django tags witch is alone in a code line """ 264 self._upto_block() 265 self.cur = self.root 266 DocNode("pass_line", self.cur, groups["pass_line"]) 227 267 self.text = None 228 268 229 def _pass through_line_repl(self, groups):230 """ Pass-through all django tags"""231 DocNode("pass through_line", self.cur, groups["passthrough_line"])232 self.text = None 233 269 def _pass_inline_repl(self, groups): 270 """ Pass-through all inline django tags""" 271 DocNode("pass_inline", self.cur, groups["pass_inline"]) 272 self.text = None 273 234 274 def _html_repl(self, groups): 235 275 """ Pass-through html code """ … … 239 279 240 280 def _text_repl(self, groups): 241 # print "_text_repl()", self.cur.kind, groups.get('break') != None 281 # print "_text_repl()", self.cur.kind, groups.get('break') != None 242 282 if self.cur.kind in ('table', 'table_row', 'bullet_list', 243 283 'number_list'): 244 284 self._upto_block() 245 285 246 286 if self.cur.kind in ('document', 'section', 'blockquote'): 247 287 self.cur = DocNode('paragraph', self.cur) 248 249 self.parse_inline(groups.get('text', ''))250 288 289 self.parse_inline(groups.get('text', u"")) 290 251 291 if groups.get('break') and self.cur.kind in ('paragraph', 252 292 'emphasis', 'strong', 'code'): 253 DocNode('break', self.cur, '')254 293 self.last_text_break = DocNode('break', self.cur, u"") 294 255 295 self.text = None 256 296 _break_repl = _text_repl … … 260 300 if not groups.get('escaped_url'): 261 301 # this url is NOT escaped 262 target = groups.get('url_target', '')302 target = groups.get('url_target', u"") 263 303 node = DocNode('link', self.cur) 264 304 node.content = target … … 268 308 # this url is escaped, we render it as text 269 309 if self.text is None: 270 self.text = DocNode('text', self.cur, u '')310 self.text = DocNode('text', self.cur, u"") 271 311 self.text.content += groups.get('url_target') 272 312 _url_target_repl = _url_repl … … 276 316 def _link_repl(self, groups): 277 317 """Handle all kinds of links.""" 278 target = groups.get('link_target', '')279 text = (groups.get('link_text', '') or '').strip()318 target = groups.get('link_target', u"") 319 text = (groups.get('link_text', u"") or u"").strip() 280 320 parent = self.cur 281 321 self.cur = DocNode('link', self.cur) … … 288 328 _link_text_repl = _link_repl 289 329 330 def _add_macro(self, macro_name, macro_args, macro_text=u""): 331 # self._upto_block() 332 node = DocNode("macro", self.cur, macro_text.strip()) 333 node.macro_name = macro_name 334 node.macro_args = macro_args.strip() 335 self.text = None 336 337 def _macro_block_repl(self, groups): 338 """Handles macros using the placeholder syntax.""" 339 #self.debug_groups(groups) 340 self._upto_block() 341 self.cur = self.root 342 self._add_macro( 343 macro_name = groups['macro_block_start'], 344 macro_text = groups.get('macro_block_text', u""), 345 macro_args = groups.get('macro_block_args', u""), 346 ) 347 self.text = None 348 _macro_block_start_repl = _macro_block_repl 349 _macro_block_args_repl = _macro_block_repl 350 _macro_block_text_repl = _macro_block_repl 351 290 352 def _macro_repl(self, groups): 291 353 """Handles macros using the placeholder syntax.""" 292 name = groups.get('macro_name', '') 293 text = (groups.get('macro_text', '') or '').strip() 294 node = DocNode('macro', self.cur, name) 295 node.args = groups.get('macro_args', '') or '' 296 DocNode('text', node, text or name) 297 self.text = None 354 macro_name = groups.get('macro_name', u"") 355 macro_args = groups.get('macro_args', u"") 356 self._add_macro(macro_name, macro_args) 357 self.text = None 358 359 # text = (groups.get('macro_text', u"") or u"").strip() 360 # node = DocNode('macro', self.cur, name) 361 # node.args = groups.get('macro_args', u"") or '' 362 # DocNode('text', node, text or name) 363 # self.text = None 298 364 _macro_name_repl = _macro_repl 299 365 _macro_args_repl = _macro_repl 300 _macro_text_repl = _macro_repl366 # _macro_text_repl = _macro_repl 301 367 302 368 def _image_repl(self, groups): 303 369 """Handles images and attachemnts included in the page.""" 304 target = groups.get('image_target', '').strip()305 text = (groups.get('image_text', '') or '').strip()370 target = groups.get('image_target', u"").strip() 371 text = (groups.get('image_text', u"") or u"").strip() 306 372 node = DocNode("image", self.cur, target) 307 373 DocNode('text', node, text or node.content) … … 315 381 316 382 def _item_repl(self, groups): 317 bullet = groups.get('item_head', u '')318 text = groups.get('item_text', u '')383 bullet = groups.get('item_head', u"") 384 text = groups.get('item_text', u"") 319 385 if bullet[-1] == '#': 320 386 kind = 'number_list' … … 371 437 self.text = None 372 438 else: 373 text = m.group('head').strip('= ') 439 text = m.group('head').strip('= ') 374 440 self.cur = DocNode('table_head', tr) 375 self.text = DocNode('text', self.cur, u '')441 self.text = DocNode('text', self.cur, u"") 376 442 self.parse_inline(text) 377 443 378 444 self.cur = tb 379 445 self.text = None … … 382 448 self._upto_block() 383 449 kind = groups.get('pre_kind', None) 384 text = groups.get('pre_text', u '')450 text = groups.get('pre_text', u"") 385 451 def remove_tilde(m): 386 452 return m.group('indent') + m.group('rest') … … 396 462 """ Transfer newline from the original markup into the html code """ 397 463 self._upto_block() 398 DocNode('line', self.cur, "")464 DocNode('line', self.cur, u"") 399 465 400 466 def _code_repl(self, groups): 401 DocNode('code', self.cur, groups.get('code_text', u '').strip())467 DocNode('code', self.cur, groups.get('code_text', u"").strip()) 402 468 self.text = None 403 469 _code_text_repl = _code_repl … … 424 490 def _escape_repl(self, groups): 425 491 if self.text is None: 426 self.text = DocNode('text', self.cur, u '')427 self.text.content += groups.get('escaped_char', u '')492 self.text = DocNode('text', self.cur, u"") 493 self.text.content += groups.get('escaped_char', u"") 428 494 429 495 def _char_repl(self, groups): 430 496 if self.text is None: 431 self.text = DocNode('text', self.cur, u'') 432 self.text.content += groups.get('char', u'') 433 434 #-------------------------------------------------------------------------- 435 436 def check_break(self): 437 """ 438 remove unused end line breaks. Should be called on every block element. 439 e.g.: 440 <p>line one<br /> 441 line two<br /> <--- remove this br-tag 442 </p> 443 """ 444 if self.cur.children == []: 445 return 446 if self.cur.children[-1].kind == "break": 447 del(self.cur.children[-1]) 448 497 self.text = DocNode('text', self.cur, u"") 498 self.text.content += groups.get('char', u"") 499 449 500 #-------------------------------------------------------------------------- 450 501 … … 455 506 if text is not None: 456 507 #if name != "char": print "%15s: %r" % (name, text) 457 if name in Rules.blockelements: 458 self.check_break() 508 #print "%15s: %r" % (name, text) 459 509 replace = getattr(self, '_%s_repl' % name) 460 510 replace(groups) … … 476 526 477 527 #-------------------------------------------------------------------------- 478 def debug(self ):528 def debug(self, start_node=None): 479 529 """ 480 530 Display the current document tree 481 531 """ 482 532 print "_"*80 483 print " document tree:" 533 534 if start_node == None: 535 start_node = self.root 536 print " document tree:" 537 else: 538 print " tree from %s:" % start_node 539 484 540 print "="*80 485 541 def emit(node, ident=0): 486 542 for child in node.children: 487 print u"%s%s " % (u" "*ident, child)543 print u"%s%s: %r" % (u" "*ident, child.kind, child.content) 488 544 emit(child, ident+4) 489 emit(s elf.root)545 emit(start_node) 490 546 print "*"*80 491 547 492 548 def debug_groups(self, groups): 493 549 print "_"*80 … … 511 567 self.parent = parent 512 568 self.kind = kind 569 570 if content: 571 content = unicode(content) 513 572 self.content = content 573 514 574 if self.parent is not None: 515 575 self.parent.children.append(self) … … 517 577 def __str__(self): 518 578 # return "DocNode kind '%s', content: %r" % (self.kind, self.content) 519 return "%s: %r" % (self.kind, self.content) 579 return "<DocNode %s: %r>" % (self.kind, self.content) 580 def __repr__(self): 581 return u"<DocNode %s: %r>" % (self.kind, self.content) 582 583 def debug(self): 584 print "_"*80 585 print "\tDocNode - debug:" 586 print "str(): %s" % self 587 print "attributes:" 588 for i in dir(self): 589 if i.startswith("_"): 590 continue 591 print "%20s: %r" % (i, getattr(self, i, "---")) 520 592 521 593 … … 549 621 picture [[www.domain.tld | {{ foo.JPG | Foo }} ]] as a link 550 622 551 END""" 552 623 END 624 625 ==== Headline 1 626 627 {% a tag 1 %} 628 629 ==== Headline 2 630 631 {% a tag 2 %} 632 633 the end 634 """ 635 636 txt = r""" 637 ==== Headline 1 638 639 The current page name: >{{ PAGE.name }}< great? 640 641 {% a tag 1 %} 642 643 ==== Headline 2 644 645 {% a tag 2 %} 646 647 some text 648 649 {% something arg1="foo" arg2="bar" arg2=3 %} 650 foobar 651 {% endsomething %} 652 653 the end 654 """ 655 656 txt = r"""A {% lucidTag page_update_list count=10 %} PyLucid plugin 657 658 {% sourcecode py %} 659 import sys 660 661 sys.stdout("Hello World!") 662 {% endsourcecode %} 663 A [[www.domain.tld|link]].""" 664 665 txt = r""" 666 ==== Headline 1 667 668 On {% a tag 1 %} line 669 line two 670 671 ==== Headline 2 672 673 {% a tag 2 %} 674 675 A block: 676 {% block %} 677 <Foo:> {{ Bar }} 678 {% endblock %} 679 end block 680 681 {% block1 arg="jo" %} 682 eofjwqp 683 {% endblock1 %} 684 685 A block without the right end block: 686 {% block1 %} 687 111 688 {% endblock2 %} 689 BBB 690 691 A block without endblock: 692 {% block3 %} 693 222 694 {% block3 %} 695 CCC 696 697 the end""" 698 # txt = r''' 699 #<<jojo>> 700 #owrej 701 #<<code>> 702 #some code 703 #<</code>> 704 #a macro: 705 #<<code ext=.css>> 706 #/* Stylesheet */ 707 #form * { 708 # vertical-align:middle; 709 #} 710 #<</code>> 711 #the end 712 #<<code>> 713 #<<code>> 714 #jup 715 #<</code>> 716 #''' 717 718 719 print "-"*80 553 720 p = Parser(txt) 554 721 document = p.parse() 555 722 p.debug() 556 723 557 724 def test_rules(rules, txt): 558 725 def display_match(match): … … 563 730 re.sub(rules, display_match, txt) 564 731 565 print "_"*80566 print "plain block rules match:"567 test_rules(Parser("").block_re, txt)568 569 print "_"*80570 print "plain inline rules match:"571 test_rules(Parser("").inline_re, txt)732 # print "_"*80 733 # print "plain block rules match:" 734 # test_rules(Parser("").block_re, txt) 735 # 736 # print "_"*80 737 # print "plain inline rules match:" 738 # test_rules(Parser("").inline_re, txt) 572 739 573 740 print "---END---" -
trunk/pylucid_project/PyLucid/system/markups/creole2html.py
r1769 r1771 41 41 """ 42 42 43 import re 43 import sys, re, traceback 44 44 45 from creole import Parser 46 47 import macros 48 49 from PyLucid.tools.utils import escape 45 50 46 51 class Rules: … … 53 58 ''' 54 59 55 class Macro(object):56 # def __init__(self):57 def source_emit(self, node):58 print node59 60 from PyLucid.tools.utils import escape61 60 class HtmlEmitter: 62 61 """ … … 70 69 ]), re.X | re.U) # for addresses 71 70 72 def __init__(self, root ):71 def __init__(self, root, verbose=1, stderr=sys.stderr): 73 72 self.root = root 74 self.macro = Macro() 73 self.verbose = verbose 74 self.stderr = stderr 75 75 76 76 def get_text(self, node): … … 188 188 189 189 def macro_emit(self, node): 190 # try: 191 # return getattr(self.macro, 192 raise NotImplementedError("Node: %r" % node.content) 190 #print node.debug() 191 macro_name = node.macro_name 192 try: 193 macro = getattr(macros, macro_name) 194 except AttributeError, e: 195 return self.error( 196 u"Macro '%s' doesn't exist" % macro_name, 197 handle_traceback = True 198 ) 199 200 try: 201 result = macro(args=node.macro_args, text=node.content) 202 except Exception, err: 203 return self.error( 204 u"Macro '%s' error: %s" % (macro_name, err), 205 handle_traceback = True 206 ) 207 208 if not isinstance(result, unicode): 209 msg = u"Macro '%s' doesn't return a unicode string!" % macro_name 210 if self.verbose>1: 211 msg += " - returns: %r, type %r" % (result, type(result)) 212 return self.error(msg) 213 214 return result 193 215 194 216 def break_emit(self, node): … … 206 228 return u"<pre>\n%s\n</pre>\n" % self.html_escape(node.content) 207 229 208 def pass through_block_emit(self, node):230 def pass_block_emit(self, node): 209 231 """ Pass-through all django template blocktags and html code lines """ 210 232 return node.content + "\n" 211 html_emit = passthrough_block_emit 212 213 def passthrough_line_emit(self, node): 233 pass_line_emit = pass_block_emit 234 html_emit = pass_block_emit 235 236 def pass_inline_emit(self, node): 214 237 """ Pass-through all django template tags """ 215 238 return node.content … … 217 240 def default_emit(self, node): 218 241 """Fallback function for emitting unknown nodes.""" 219 raise TypeError242 raise NotImplementedError("Node '%s' unknown" % node.kind) 220 243 221 244 def emit_children(self, node): … … 233 256 return self.emit_node(self.root) 234 257 258 def error(self, text, handle_traceback=False): 259 """ 260 Error Handling. 261 """ 262 if self.verbose>1 and handle_traceback: 263 self.stderr.write( 264 "<pre>%s</pre>" % traceback.format_exc() 265 ) 266 267 if self.verbose>0: 268 return u"[Error: %s]" % text 269 else: 270 # No error output 271 return u"" 272 235 273 if __name__=="__main__": 236 274 txt = r"""== a headline … … 260 298 261 299 END""" 300 301 302 txt = r""" 303 ==== Headline 1 304 305 On {% a tag 1 %} line 306 line two 307 308 ==== Headline 2 309 310 {% a tag 2 %} 311 312 A block: 313 {% block %} 314 <Foo:> {{ Bar }} 315 {% endblock %} 316 end block 317 318 {% block1 arg="jo" %} 319 eofjwqp 320 {% endblock1 %} 321 322 A block without the right end block: 323 {% block1 %} 324 111 325 {% endblock2 %} 326 BBB 327 328 A block without endblock: 329 {% block3 %} 330 222 331 {% block3 %} 332 CCC 333 334 the end""" 262 335 263 336 print "-"*80 -
trunk/pylucid_project/tests/markup_creole.py
r1769 r1771 58 58 """ 59 59 document = Parser(txt).parse() 60 out_string = HtmlEmitter(document ).emit()60 out_string = HtmlEmitter(document, verbose=1).emit() 61 61 #print ">>>%r<<<" % out_string 62 62 return out_string … … 138 138 """) 139 139 140 141 142 140 def test_django1(self): 143 141 """ … … 149 147 The current page name: >{{ PAGE.name }}< great? 150 148 A {% lucidTag page_update_list count=10 %} PyLucid plugin 151 {% sourcecode py %} 152 import sys 153 154 sys.stdout("Hello World!") 155 {% endsourcecode %} 149 {% block %} 150 FooBar 151 {% endblock %} 156 152 A [[www.domain.tld|link]]. 157 153 a {{/image.jpg|My Image}} image … … 162 158 <p>The current page name: >{{ PAGE.name }}< great?<br /> 163 159 A {% lucidTag page_update_list count=10 %} PyLucid plugin</p> 164 {% sourcecode py %} 165 import sys 166 167 sys.stdout("Hello World!") 168 {% endsourcecode %} 160 {% block %} 161 FooBar 162 {% endblock %} 169 163 <p>A <a href="www.domain.tld">link</a>.<br /> 170 164 a <img src="/image.jpg" alt="My Image"> image</p> … … 172 166 <p>no image: {{ foo|bar }}!<br /> 173 167 picture <a href="www.domain.tld"><img src="foo.JPG" alt="Foo"></a> as a link</p> 168 """) 169 170 def test_django2(self): 171 self.assertCreole(r""" 172 ==== Headline 1 173 174 On {% a tag 1 %} line 175 line two 176 177 ==== Headline 2 178 179 {% a tag 2 %} 180 181 Right block with a end tag: 182 {% block %} 183 <Foo:> {{ Bar }} 184 {% endblock %} 185 end block 186 187 A block without the right end block: 188 {% block1 %} 189 not matched 190 {% endblock2 %} 191 BBB 192 193 A block without endblock: 194 {% noblock3 %} 195 not matched 196 {% noblock3 %} 197 CCC 198 """, """ 199 <h4>Headline 1</h4> 200 201 <p>On {% a tag 1 %} line<br /> 202 line two</p> 203 204 <h4>Headline 2</h4> 205 206 {% a tag 2 %} 207 208 <p>Right block with a end tag:</p> 209 {% block %} 210 <Foo:> {{ Bar }} 211 {% endblock %} 212 <p>end block</p> 213 214 <p>A block without the right end block:<br /> 215 {% block1 %}<br /> 216 not matched<br /> 217 {% endblock2 %}<br /> 218 BBB</p> 219 220 <p>A block without endblock:<br /> 221 {% noblock3 %}<br /> 222 not matched<br /> 223 {% noblock3 %}<br /> 224 CCC</p> 174 225 """) 175 226 … … 477 528 This is a normal Text block witch would 478 529 escape html chars like < and > ;) 530 531 html code must start and end with a tag: 479 532 <p>this <strong class="my">html code</strong> line pass-through</p> 480 end 533 this works. 534 535 this: 536 <p>didn't<br /> 537 match</p> 538 539 <p> 540 didn't match 541 </p> 542 543 <p>didn't match,too.< p > 481 544 """, """ 482 545 <p>This is a normal Text block witch would<br /> 483 546 escape html chars like < and > ;)</p> 547 548 <p>html code must start and end with a tag:</p> 484 549 <p>this <strong class="my">html code</strong> line pass-through</p> 485 <p>end</p> 550 <p>this works.</p> 551 552 <p>this:<br /> 553 <p>didn\'t<br /><br /> 554 match</p></p> 555 556 <p><p><br /> 557 didn\'t match<br /> 558 </p></p> 559 560 <p><p>didn\'t match,too.< p ></p> 561 """) 562 563 def test_macro_html1(self): 564 self.assertCreole(r""" 565 <<a_not_existing_macro>> 566 567 <<code>> 568 some code 569 <</code>> 570 571 a macro: 572 <<code>> 573 <<code>> 574 the sourcecode 575 <</code>> 576 """, r""" 577 <p>[Error: Macro 'a_not_existing_macro' doesn't exist]</p> 578 <fieldset class="pygments_code"> 579 <legend class="pygments_code"><small title="no lexer matching the text found">unknown type</small></legend> 580 <pre><code>some code</code></pre> 581 </fieldset> 582 <p>a macro:</p> 583 <fieldset class="pygments_code"> 584 <legend class="pygments_code"><small title="no lexer matching the text found">unknown type</small></legend> 585 <pre><code><<code>> 586 the sourcecode</code></pre> 587 </fieldset> 588 """) 589 590 def test_macro_html2(self): 591 self.assertCreole(r""" 592 html macro: 593 <<html>> 594 <p><<this is 'html'>></p> 595 <</html>> 596 """, r""" 597 <p>html macro:</p> 598 <p><<this is 'html'>></p> 599 """) 600 601 def test_macro_pygments_code(self): 602 self.assertCreole(r""" 603 a macro: 604 <<code ext=.css>> 605 /* Stylesheet */ 606 form * { 607 vertical-align:middle; 608 } 609 <</code>> 610 the end 611 """, """ 612 <p>a macro:</p> 613 <fieldset class="pygments_code"> 614 <legend class="pygments_code">CSS</legend><table class="pygmentstable"><tr><td class="linenos"><pre>1 615 2 616 3 617 4</pre></td><td class="code"><div class="pygments"><pre><span class="c">/* Stylesheet */</span> 618 <span class="nt">form</span> <span class="o">*</span> <span class="p">{</span> 619 <span class="k">vertical-align</span><span class="o">:</span><span class="k">middle</span><span class="p">;</span> 620 <span class="p">}</span> 621 </pre></div> 622 </td></tr></table></fieldset> 623 <p>the end</p> 486 624 """) 487 625 -
trunk/pylucid_project/tests/utils/unittest_addons.py
r1761 r1771 48 48 try: 49 49 msg = self.args[0] 50 51 """ 52 Get the right split_string is not easy. There are three kinds: 53 u"foo" != "bar" 54 u'foo' != "bar" 55 u"foo" != 'bar' 56 u'foo' != 'bar' 57 """ 58 msg = msg.lstrip("u") # u"foobar" -> "foobar" 59 first_quote = msg[0] 60 last_quote = msg[-1] 61 split_string = "%s != %s" % (first_quote, last_quote) 62 msg = msg.strip(first_quote + last_quote) 50 63 51 # strip ' out 52 if msg.startswith("u'"): 53 msg = msg[2:-1] 54 else: 55 msg = msg[1:-1] 56 64 # # strip ' out 65 # if msg.startswith("u'"): 66 # msg = msg[2:-1] 67 # else: 68 # msg = msg[1:-1] 69 # 70 # if "' != '" in msg: 71 # split_string = "' != '" 72 # elif '" != "' in msg: 73 # split_string = '" != "' 74 # else: 75 # msg = self._format_output(msg) 76 # return "Unknwon error output: %r" % msg 77 57 78 try: 58 block1, block2 = msg.split( "' != '")59 except ValueError :79 block1, block2 = msg.split(split_string) 80 except ValueError, err: 60 81 msg = self._format_output(msg) 61 82 return ( 62 " Format error in output\n"83 "Can't split error output: %r\n" 63 84 "Info:\n%s" 64 ) % msg85 ) % (err, msg) 65 86 66 87 #~ block1 = block1.rstrip("\\n")
