~ubuntu-branches/ubuntu/intrepid/moin/intrepid-updates

« back to all changes in this revision

Viewing changes to MoinMoin/parser/wiki.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-02-14 16:09:24 UTC
  • mfrom: (0.2.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20060214160924-fyrx3gvknzqvt4vj
Tags: 1.5.2-1ubuntu1
Drop python2.3 package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
    dl_rule = ur"^\s+.*?::\s"
54
54
 
55
55
    # the big, fat, ugly one ;)
56
 
    formatting_rules = ur"""(?P<ent_numeric>&#\d{1,5};)
 
56
    formatting_rules = ur"""(?P<ent_numeric>&#(\d{1,5}|x[0-9a-fA-F]+);)
57
57
(?:(?P<emph_ibb>'''''(?=[^']+'''))
58
58
(?P<emph_ibi>'''''(?=[^']+''))
59
59
(?P<emph_ib_or_bi>'{5}(?=[^']))
72
72
(?P<macro>\[\[(%%(macronames)s)(?:\(.*?\))?\]\]))
73
73
(?P<ol>%(ol_rule)s)
74
74
(?P<dl>%(dl_rule)s)
75
 
(?P<li>^\s+\*?\s*)
 
75
(?P<li>^\s+\*\s*)
 
76
(?P<li_none>^\s+\.\s*)
 
77
(?P<indent>^\s+)
76
78
(?P<tableZ>\|\| $)
77
79
(?P<table>(?:\|\|)+(?:<[^>]*?>)?(?!\|? $))
78
80
(?P<heading>^\s*(?P<hmarker>=+)\s.*\s(?P=hmarker) $)
83
85
(?P<email>[-\w._+]+\@[\w-]+(\.[\w-]+)+)
84
86
(?P<smiley>(?<=\s)(%(smiley)s)(?=\s))
85
87
(?P<smileyA>^(%(smiley)s)(?=\s))
 
88
(?P<ent_symbolic>&[a-zA-Z]+;)
86
89
(?P<ent>[<>&])
87
90
(?P<wikiname_bracket>\[".*?"\])
88
91
(?P<tt_bt>`.*?`)"""  % {
96
99
        'smiley': u'|'.join(map(re.escape, config.smileys.keys()))}
97
100
 
98
101
    # Don't start p before these 
99
 
    no_new_p_before = ("heading rule table tableZ tr td ul ol dl dt dd li "
100
 
                       "processor macro pre")
101
 
    no_new_p_before = dict(zip(no_new_p_before.split(), [1] * len(no_new_p_before)))
 
102
    no_new_p_before = ("heading rule table tableZ tr td "
 
103
                       "ul ol dl dt dd li li_none indent "
 
104
                       "macro processor pre")
 
105
    no_new_p_before = no_new_p_before.split()
 
106
    no_new_p_before = dict(zip(no_new_p_before, [1] * len(no_new_p_before)))
102
107
 
103
108
    def __init__(self, raw, request, **kw):
104
109
        self.raw = raw
423
428
            return self.attachment(words, pretty_url=1)
424
429
 
425
430
        if wikiutil.isPicture(words[1]) and re.match(self.url_rule, words[1]):
426
 
            return (self.formatter.url(1, words[0], css='external', unescaped=1) +
 
431
            return (self.formatter.url(1, words[0], css='external', do_escape=0) +
427
432
                    self.formatter.image(title=words[0], alt=words[0], src=words[1]) +
428
433
                    self.formatter.url(0))
429
434
        else:
430
 
            return (self.formatter.url(1, words[0], css='www', unescaped=1) +
 
435
            return (self.formatter.url(1, words[0], css=scheme, do_escape=0) +
431
436
                    self.formatter.text(words[1]) +
432
437
                    self.formatter.url(0))
433
438
 
446
451
        #        '<': '&lt;',
447
452
        #        '>': '&gt;'}[word]
448
453
 
449
 
 
450
454
    def _ent_numeric_repl(self, word):
451
 
        """Handle numeric SGML entities."""
452
 
        return self.formatter.rawHTML(word)
453
 
 
 
455
        """Handle numeric (decimal and hexadecimal) SGML entities."""
 
456
        return self.formatter.rawHTML(word)
 
457
 
 
458
    def _ent_symbolic_repl(self, word):
 
459
        """Handle symbolic SGML entities."""
 
460
        return self.formatter.rawHTML(word)
 
461
    
 
462
    def _indent_repl(self, match):
 
463
        """Handle pure indentation (no - * 1. markup)."""
 
464
        result = []
 
465
        if not self.in_li:
 
466
            self._close_item(result)
 
467
            self.in_li = 1
 
468
            css_class = None
 
469
            if self.line_was_empty and not self.first_list_item:
 
470
                css_class = 'gap'
 
471
            result.append(self.formatter.listitem(1, css_class=css_class, style="list-style-type:none"))
 
472
        return ''.join(result)
 
473
 
 
474
    def _li_none_repl(self, match):
 
475
        """Handle type=none (" .") lists."""
 
476
        result = []
 
477
        self._close_item(result)
 
478
        self.in_li = 1
 
479
        css_class = None
 
480
        if self.line_was_empty and not self.first_list_item:
 
481
            css_class = 'gap'
 
482
        result.append(self.formatter.listitem(1, css_class=css_class, style="list-style-type:none"))
 
483
        return ''.join(result)
454
484
 
455
485
    def _li_repl(self, match):
456
 
        """Handle bullet lists."""
 
486
        """Handle bullet (" *") lists."""
457
487
        result = []
458
 
        indented_only = (match == (" " * len(match)))
459
 
        if indented_only and self.in_li:
460
 
            return ''
461
 
            
462
488
        self._close_item(result)
463
 
        #self.inhibit_p = 1
464
489
        self.in_li = 1
465
 
        css_class = ''
 
490
        css_class = None
466
491
        if self.line_was_empty and not self.first_list_item:
467
492
            css_class = 'gap'
468
 
        if indented_only:
469
 
            result.append(self.formatter.listitem(1, css_class=css_class,
470
 
                                                  style="list-style-type:none"))
471
 
        else:
472
 
            result.append(self.formatter.listitem(1, css_class=css_class))
473
 
        # Suspected p!
474
 
        ## result.append(self.formatter.paragraph(1))
 
493
        result.append(self.formatter.listitem(1, css_class=css_class))
475
494
        return ''.join(result)
476
495
 
477
 
 
478
496
    def _ol_repl(self, match):
479
497
        """Handle numbered lists."""
480
498
        return self._li_repl(match)
516
534
        #        self.inhibit_p = 1
517
535
    
518
536
        # Close lists while char-wise indent is greater than the current one
519
 
        while ((self._indent_level() > new_level) or
520
 
               ( new_level and
521
 
                (self._indent_level() == new_level) and
522
 
                (self.list_types[-1]) != list_type)):
 
537
        #while ((self._indent_level() > new_level) or
 
538
        #       ( new_level and
 
539
        #        (self._indent_level() == new_level) and
 
540
        #        (self.list_types[-1]) != list_type)):
 
541
        while self._indent_level() > new_level:
523
542
            self._close_item(close)
524
543
            if self.list_types[-1] == 'ol':
525
544
                tag = self.formatter.number_list(0)
564
583
            ##self.inhibit_p = 1
565
584
            self.in_li = 0
566
585
            self.in_dd = 0
 
586
            
567
587
        # If list level changes, close an open table
568
588
        if self.in_table and (open or close):
569
589
            close[0:0] = [self.formatter.table(0)]
580
600
        result = []
581
601
        #result.append("<!-- _undent start -->\n")
582
602
        self._close_item(result)
583
 
        for type in self.list_types:
 
603
        for type in self.list_types[::-1]:
584
604
            if type == 'ol':
585
605
                result.append(self.formatter.number_list(0))
586
606
            elif type == 'dl':
672
692
                        'arg': arg, 'key': key}
673
693
                else:
674
694
                    attrs['bgcolor'] = '"#%s"' % arg
675
 
            elif key == '=':
676
 
                arg = parser.get_token()
677
 
                this_key = attrdef.split('=')[0]
678
 
                attrs[this_key] = arg
679
695
            else:
680
 
                msg = ""
 
696
                msg = None
681
697
            #print "key: %s\nattrs: %s" % (key, str(attrs))
682
698
            return self.formatter.rawHTML(msg)
683
699
 
825
841
    def _macro_repl(self, word):
826
842
        """Handle macros ([[macroname]])."""
827
843
        macro_name = word[2:-2]
828
 
        #self.inhibit_p = 1 # fixes UserPreferences, but makes new trouble!
 
844
        self.inhibit_p = 1 # 0 fixes UserPreferences, but makes new trouble!
829
845
 
830
846
        # check for arguments
831
847
        args = None
856
872
                ###result.append(u'<span class="info">[add text before match: <tt>"%s"</tt>]</span>' % line[lastpos:match.start()])
857
873
                
858
874
                if not (self.inhibit_p or self.in_pre or self.formatter.in_p):
859
 
                    result.append(self.formatter.paragraph(1))
 
875
                    result.append(self.formatter.paragraph(1, css_class="line879"))
860
876
                result.append(self.formatter.text(line[lastpos:match.start()]))
861
877
            
862
878
            # Replace match with markup
868
884
        # No match: Add paragraph with the text of the line
869
885
        if not (self.in_pre or self.inhibit_p or
870
886
                self.formatter.in_p) and lastpos < len(line):
871
 
            result.append(self.formatter.paragraph(1))
 
887
            result.append(self.formatter.paragraph(1, css_class="line886"))
872
888
        result.append(self.formatter.text(line[lastpos:]))
873
889
        return u''.join(result)
874
890
 
885
901
                    # Open p for certain types
886
902
                    if not (self.inhibit_p or self.formatter.in_p
887
903
                            or self.in_pre or (type in self.no_new_p_before)):
888
 
                        result.append(self.formatter.paragraph(1))
 
904
                        result.append(self.formatter.paragraph(1, css_class="line903"))
889
905
                    
890
906
                    # Get replace method and replece hit
891
907
                    replace = getattr(self, '_' + type + '_repl')
998
1014
                    self.processor = None
999
1015
 
1000
1016
                    # send rest of line through regex machinery
1001
 
                    line = line[endpos+3:]                    
 
1017
                    line = line[endpos+3:]
 
1018
                    if not line.strip(): # just in the case "}}} " when we only have blanks left...
 
1019
                        continue
1002
1020
            else:
1003
1021
                # we don't have \n as whitespace any more
1004
1022
                # This is the space between lines we join to one paragraph
1011
1029
                        self.in_table = 0
1012
1030
                    # CHANGE: removed check for not self.list_types
1013
1031
                    # p should close on every empty line
1014
 
                    if (self.formatter.in_p):
 
1032
                    if self.formatter.in_p:
1015
1033
                        self.request.write(self.formatter.paragraph(0))
1016
1034
                    self.line_is_empty = 1
1017
1035
                    continue
1040
1058
                            indtype = "dl"
1041
1059
 
1042
1060
                # output proper indentation tags
1043
 
                self.request.write(self._indent_to(indlen, indtype, numtype,
1044
 
                                                   numstart))
 
1061
                self.request.write(self._indent_to(indlen, indtype, numtype, numstart))
1045
1062
 
1046
1063
                # Table mode
1047
1064
                # TODO: move into function?                
1049
1066
                    and line[-3:] == "|| " and len(line) >= 5 + indlen):
1050
1067
                    # Start table
1051
1068
                    if self.list_types and not self.in_li:
1052
 
                        self.request.write(self.formatter.listitem
1053
 
                                           (1, style="list-style-type:none"))
 
1069
                        self.request.write(self.formatter.listitem(1, style="list-style-type:none"))
1054
1070
                        ## CHANGE: no automatic p on li
1055
1071
                        ##self.request.write(self.formatter.paragraph(1))
1056
1072
                        self.in_li = 1
1077
1093
            formatted_line = self.scan(scan_re, line)
1078
1094
            self.request.write(formatted_line)
1079
1095
 
1080
 
            if self.in_pre:
 
1096
            if self.in_pre == 3:
1081
1097
                self.request.write(self.formatter.linebreak())
1082
1098
 
1083
1099
        # Close code displays, paragraphs, tables and open lists
1103
1119
                self.processor_is_parser = 1
1104
1120
            except wikiutil.PluginMissingError:
1105
1121
                self.processor = None
 
1122
 
 
1123