Ticket #2232: oneliner_simplify_blocks.patch
| File oneliner_simplify_blocks.patch, 4.3 KB (added by cboos, 7 years ago) |
|---|
-
trac/wiki/tests/wiki-tests.txt
394 394 <pre class="wiki">Preformatted text. 395 395 </pre> 396 396 ------------------------------ 397 {{{...}}} 398 ============================== 397 399 {{{ 398 Preformatted text. 400 Outer block. 401 {{{ 402 Inner block. 399 403 }}} 404 }}} 405 ------------------------------ 406 <pre class="wiki">Outer block. 407 {{{ 408 Inner block. 409 }}} 410 </pre> 411 ------------------------------ 412 {{{...}}} 400 413 ============================== 414 Block 401 415 {{{ 402 #!default 403 Preformatted text. 416 number one 404 417 }}} 418 and block 419 {{{ 420 number two 421 }}} 405 422 ------------------------------ 406 <pre class="wiki">Preformatted text. 423 <p> 424 Block 425 </p> 426 <pre class="wiki">number one 407 427 </pre> 428 <p> 429 and block 430 </p> 431 <pre class="wiki">number two 432 </pre> 408 433 ------------------------------ 434 Block {{{...}}} 435 and block{{{...}}} 436 ============================== 409 437 {{{ 410 438 #!default 411 439 Preformatted text. 412 440 }}} 441 ------------------------------ 442 <pre class="wiki">Preformatted text. 443 </pre> 444 ------------------------------ 445 {{{#!default ...}}} 413 446 ============================== 414 447 {{{ 415 448 #!/bin/sh … … 420 453 echo "foo" 421 454 </pre> 422 455 ------------------------------ 423 {{{ 424 #!/bin/sh 425 echo "foo" 426 }}} 456 {{{#!/bin/sh ...}}} 427 457 ============================== 428 458 {{{ 429 459 #!html … … 432 462 ------------------------------ 433 463 <p>Hello World</p> 434 464 ------------------------------ 435 {{{ 436 #!html 437 <p>Hello World</p> 438 }}} 465 {{{#!html ...}}} 439 466 ============================== 440 467 {{{ 441 468 #!html … … 448 475 </pre> 449 476 </div> 450 477 ------------------------------ 451 {{{ 452 #!html 453 <script>alert("");</script> 454 }}} 478 {{{#!html ...}}} 455 479 ============================== 456 480 {{{ 457 481 #!html … … 464 488 </pre> 465 489 </div> 466 490 ------------------------------ 467 {{{ 468 #!html 469 <div onclick="alert(<i>)">Click me</div> 470 }}}</i> 491 {{{#!html ...}}} 471 492 ============================== 472 493 ^superscript^, ,,subscript,,, normal. 473 494 ------------------------------ … … 536 557 </p> 537 558 ------------------------------ 538 559 Test comment blocks 539 {{{540 #!comment541 This is simply removed from the output542 }}}543 560 ============================== 544 561 Inline [[comment(This should not be seen)]] comment 545 562 ------------------------------ -
trac/wiki/formatter.py
637 637 """ 638 638 flavor = 'oneliner' 639 639 640 _non_nested_block_re = re.compile(r"(?:^|\n)\{\{\{(?:\n(#![\w+-/]+))?" 641 r"(?:\n([^{}]|\{(?!\{\{)|\}(?!\}\}))+)+" 642 r"\}\}\}") 643 _final_block_re = re.compile(r"(?:^|\n)\{\|\{(.*?)\}\|\}") 644 640 645 def __init__(self, env, absurls=0, db=None): 641 646 Formatter.__init__(self, env, None, absurls, db) 642 647 643 648 # Override a few formatters to disable some wiki syntax in "oneliner"-mode 649 def _inlinecode_formatter(self, match, fullmatch): return match 644 650 def _list_formatter(self, match, fullmatch): return match 645 651 def _indent_formatter(self, match, fullmatch): return match 646 652 def _heading_formatter(self, match, fullmatch): return match … … 664 670 self.out = out 665 671 self._open_tags = [] 666 672 667 result = re.sub(self.rules, self.replace, util.escape(text.strip(), False)) 673 result = text.strip() 674 675 # Simplify code blocks 676 def simplify(fullmatch): 677 processor = fullmatch.group(1) 678 if processor == '#!comment': 679 return '' 680 elif processor: 681 return '\n{|{%s ...}|}' % processor 682 elif '\n' in fullmatch.group(): 683 return '\n{|{...}|}' 684 else: 685 return '<tt>%s</tt>' % match[3:-3] 686 687 old = '' 688 while old != result: 689 old = result 690 result = re.sub(self._non_nested_block_re, simplify, old) 691 result = re.sub(self._final_block_re, lambda m: '{{{%s}}}' % m.group(1), 692 old) 693 result = re.sub(self.rules, self.replace, util.escape(result, False)) 694 668 695 # Close all open 'one line'-tags 669 696 result += self.close_tag(None) 697 670 698 out.write(result) 671 699 672 700
