Attachment 'formatInMemory.py'

Download

   1     def formatInMemory(self, formatter):
   2         """ For each line, scan through looking for magic
   3             strings, outputting verbatim any intervening text.
   4         """
   5         self.formatter = formatter
   6         self.hilite_re = self.formatter.page.hilite_re
   7         self.output = ''
   8 
   9         # prepare regex patterns
  10         rules = self.formatting_rules.replace('\n', '|')
  11         if config.allow_extended_names:
  12             rules = rules + r'|(?P<wikiname_bracket>\[".*?"\])'
  13         if config.bang_meta:
  14             rules = r'(?P<notword>!%(word_rule)s)|%(rules)s' % {
  15                 'word_rule': self.word_rule,
  16                 'rules': rules,
  17             }
  18         if config.backtick_meta:
  19             rules = rules + r'|(?P<tt_bt>`.*?`)'
  20         if config.allow_numeric_entities:
  21             rules = r'(?P<ent_numeric>&#\d{1,5};)|' + rules
  22 
  23         scan_re = re.compile(rules)
  24         number_re = re.compile(self.ol_rule)
  25         term_re = re.compile(self.dl_rule)
  26         indent_re = re.compile("^\s*")
  27         eol_re = re.compile(r'\r?\n')
  28 
  29         # get text and replace TABs
  30         rawtext = self.raw.expandtabs()
  31 
  32         # go through the lines
  33         self.lineno = 0
  34         self.lines = eol_re.split(rawtext)
  35         self.line_is_empty = 0
  36 
  37         for line in self.lines:
  38             self.lineno = self.lineno + 1
  39             self.table_rowstart = 1
  40             self.line_was_empty = self.line_is_empty
  41             self.line_is_empty = 0
  42             self.first_list_item = 0
  43             self.inhibit_p = 0
  44 
  45             if self.in_pre:
  46                 # still looking for processing instructions
  47                 if self.in_pre == 1:
  48                     self.processor = None
  49                     processor_name = ''
  50                     if (line.strip()[:2] == "#!"):
  51                         from MoinMoin.processor import processors
  52                         processor_name = line.strip()[2:].split()[0]
  53                         self.processor = wikiutil.importPlugin("processor", processor_name, "process")
  54                         if not self.processor and (line.find('python') > 0):
  55                             from MoinMoin.processor.Colorize import process
  56                             self.processor = process
  57                             processor_name = "Colorize"
  58                     if self.processor:
  59                         self.in_pre = 2
  60                         self.colorize_lines = [line]
  61                         self.processor_name = processor_name
  62                         continue
  63                     else:
  64                         #self.request.write(self.formatter.preformatted(1))
  65                         self.output += self.formatter.preformatted(1)
  66                         self.in_pre = 3
  67                 if self.in_pre == 2:
  68                     # processing mode
  69                     endpos = line.find("}}}")
  70                     if endpos == -1:
  71                         self.colorize_lines.append(line)
  72                         continue
  73                     if line[:endpos]:
  74                         self.colorize_lines.append(line[:endpos])
  75                     #self.request.write(self.formatter.processor(self.processor_name, self.colorize_lines))
  76                     self.output += self.formatter.processor(self.processor_name, self.colorize_lines)
  77                     del self.colorize_lines
  78                     self.in_pre = 0
  79                     self.processor = None
  80 
  81                     # send rest of line through regex machinery
  82                     line = line[endpos+3:]                    
  83             else:
  84                 # paragraph break on empty lines
  85                 if not line.strip():
  86                     #self.request.write("<!-- empty line start -->\n")
  87                     if self.formatter.in_p:
  88                         #self.request.write(self.formatter.paragraph(0))
  89                         self.output += self.formatter.paragraph(0)
  90                     if self.in_table:
  91                         #self.request.write(self.formatter.table(0))
  92                         self.putput += self.formatter.table(0)
  93                         self.in_table = 0
  94                     self.line_is_empty = 1
  95                     #self.request.write("<!-- empty line end -->\n")
  96                     continue
  97 
  98                 # check indent level
  99                 indent = indent_re.match(line)
 100                 indlen = len(indent.group(0))
 101                 indtype = "ul"
 102                 numtype = None
 103                 numstart = None
 104                 if indlen:
 105                     match = number_re.match(line)
 106                     if match:
 107                         numtype, numstart = match.group(0).strip().split('.')
 108                         numtype = numtype[0]
 109 
 110                         if numstart and numstart[0] == "#":
 111                             numstart = int(numstart[1:])
 112                         else:
 113                             numstart = None
 114 
 115                         indtype = "ol"
 116                     else:
 117                         match = term_re.match(line)
 118                         if match:
 119                             indtype = "dl"
 120 
 121                 # output proper indentation tags
 122                 #self.request.write("<!-- inhibit_p==%d -->\n" % self.inhibit_p)
 123                 #self.request.write("<!-- #%d calling _indent_to -->\n" % self.lineno)
 124                 
 125                 #self.request.write(self._indent_to(indlen, indtype, numtype, numstart))
 126                 self.output += self._indent_to(indlen, indtype, numtype, numstart)
 127                 
 128                 #self.request.write("<!-- #%d after calling _indent_to -->\n" % self.lineno)
 129                 #self.request.write("<!-- inhibit_p==%d -->\n" % self.inhibit_p)
 130 
 131                 # start or end table mode
 132                 if not self.in_table and line[indlen:indlen+2] == "||" and line[-2:] == "||":
 133                     attrs, attrerr = self._getTableAttrs(line[indlen+2:])
 134                     #self.request.write(self.formatter.table(1, attrs) + attrerr)
 135                     self.output += self.formatter.table(1, attrs) + attrerr
 136                     self.in_table = self.lineno
 137                 elif self.in_table and not(line[:2]=="##" or # intra-table comments should not break a table 
 138                     line[indlen:indlen+2] == "||" and line[-2:] == "||"):
 139                     #self.request.write(self.formatter.table(0))
 140                     self.output += self.formatter.table(0)
 141                     self.in_table = 0
 142 
 143             # convert line from wiki markup to HTML and print it
 144             if not self.in_pre:   # we don't want to have trailing blanks in pre
 145                 line = line + " " # we don't have \n as whitespace any more
 146 
 147             formatted_line = self.scan(scan_re, line) # this also sets self.inhibit_p as side effect!
 148             
 149             #self.request.write("<!-- inhibit_p==%d -->\n" % self.inhibit_p)
 150             if not (self.inhibit_p or self.in_pre or self.in_table or self.formatter.in_p):
 151                 #self.request.write(self.formatter.paragraph(1))
 152                 self.output += self.formatter.paragraph(1)
 153 
 154             #self.request.write("<!-- %s\n     start -->\n" % line)
 155             
 156             #self.request.write(formatted_line)
 157             self.output += formatted_line
 158             
 159             #self.request.write("<!-- end -->\n")
 160 
 161             if self.in_pre:
 162                 #self.request.write(self.formatter.linebreak())
 163                 self.output += self.formatter.linebreak()
 164             #if self.in_li:
 165             #    self.in_li = 0
 166             #    self.request.write(self.formatter.listitem(0))
 167 
 168         # close code displays, paragraphs, tables and open lists
 169         if self.in_pre: self.output += self.formatter.preformatted(0)
 170         if self.formatter.in_p: self.output += self.formatter.paragraph(0)
 171         if self.in_table: self.output += self.formatter.table(0)
 172         self.output += self._undent()
 173         return self.output

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2004-06-16 03:18:22, 2.1 KB) [[attachment:ViewTrackbacks.py]]
  • [get | view] (2004-06-19 23:54:48, 1.4 KB) [[attachment:blogpost.py]]
  • [get | view] (2004-06-28 00:47:23, 0.5 KB) [[attachment:footnotediff.txt]]
  • [get | view] (2004-06-19 23:45:08, 1.3 KB) [[attachment:form.py.diff]]
  • [get | view] (2004-06-28 00:47:09, 7.9 KB) [[attachment:formatInMemory.py]]
  • [get | view] (2004-06-16 03:18:15, 4.9 KB) [[attachment:trackback.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.