Attachment 'Include_and_TableOfContents_patch_against_280.patch'

Download

   1 --- orig/MoinMoin/formatter/text_html.py
   2 +++ mod/MoinMoin/formatter/text_html.py
   3 @@ -31,6 +31,7 @@
   4          self._in_code = 0
   5          self._base_depth = 0
   6          self._show_section_numbers = None
   7 +        self._is_included = False
   8  
   9          if not hasattr(request, '_fmt_hd_counters'):
  10              request._fmt_hd_counters = []
  11 @@ -197,7 +198,11 @@
  12          # remember depth of first heading, and adapt counting depth accordingly
  13          if not self._base_depth:
  14              self._base_depth = depth
  15 -        count_depth = max(depth - (self._base_depth - 1), 1)
  16 +
  17 +        if not self._is_included:
  18 +            count_depth = max(depth - (self._base_depth - 1), 1)
  19 +        else:
  20 +            count_depth = depth
  21  
  22          # check numbering, possibly changing the default
  23          if self._show_section_numbers is None:
  24 
  25 
  26 --- orig/MoinMoin/macro/Include.py
  27 +++ mod/MoinMoin/macro/Include.py
  28 @@ -19,7 +19,7 @@
  29  
  30  _sysmsg = '<p><strong class="%s">%s</strong></p>'
  31  _arg_heading = r'(?P<heading>,)\s*(|(?P<hquote>[\'"])(?P<htext>.+?)(?P=hquote))'
  32 -_arg_level = r',\s*(?P<level>\d+)'
  33 +_arg_level = r',\s*(?P<level>\d*)'
  34  _arg_from = r'(,\s*from=(?P<fquote>[\'"])(?P<from>.+?)(?P=fquote))?'
  35  _arg_to = r'(,\s*to=(?P<tquote>[\'"])(?P<to>.+?)(?P=tquote))?'
  36  _arg_sort = r'(,\s*sort=(?P<sort>(ascending|descending)))?'
  37 @@ -45,7 +45,7 @@
  38  
  39  Dependencies = ["pages"] # included page
  40  
  41 -def execute(macro, text, args_re=re.compile(_args_re_pattern)):
  42 +def execute(macro, text, args_re=re.compile(_args_re_pattern), called_by_toc=0):
  43      _ = macro.request.getText
  44  
  45      # return immediately if getting links for the current page
  46 @@ -160,6 +160,10 @@
  47          ##result.append("*** f=%s t=%s ***" % (from_re, to_re))
  48          ##result.append("*** f=%d t=%d ***" % (from_pos, to_pos))
  49  
  50 +        if called_by_toc:
  51 +            result.append(inc_page.get_raw_body())
  52 +            continue
  53 +
  54          # edit icon
  55          edit_icon = inc_page.link_to(macro.request,
  56              macro.request.theme.make_icon("edit"),
  57 @@ -177,8 +181,10 @@
  58              if print_mode:
  59                  result.append(macro.formatter.heading(level, heading))
  60              else:
  61 +                import sha
  62                  result.append(macro.formatter.heading(level,
  63                      inc_page.link_to(macro.request, heading, css_class="include-heading-link"),
  64 +                    id="head-"+sha.new(inc_name + heading).hexdigest(),
  65                      icons=edit_icon.replace('<img ', '<img align="right" ')))
  66  
  67          # set or increment include marker
  68 @@ -189,7 +195,17 @@
  69          strfile = cStringIO.StringIO()
  70          macro.request.redirect(strfile)
  71          try:
  72 +            inc_page.formatter._is_included = True
  73 +            # caching prevents Include macro from working correctly,
  74 +            # especially with "from" and "to" parameter.
  75 +            # so disable caching feature temporarily when showing the page.
  76 +            caching_flag = False
  77 +            if "text_html" in config.caching_formats:
  78 +                caching_flag = True
  79 +                config.caching_formats.remove("text_html")
  80              inc_page.send_page(macro.request, content_only=1, content_id="Include_%s" % wikiutil.quoteWikiname(inc_page.page_name) )
  81 +            if caching_flag:
  82 +                config.caching_formats.append("text_html")
  83              result.append(strfile.getvalue())
  84          finally:
  85              macro.request.redirect()
  86 
  87 
  88 --- orig/MoinMoin/macro/TableOfContents.py
  89 +++ mod/MoinMoin/macro/TableOfContents.py
  90 @@ -10,11 +10,64 @@
  91  
  92  # Imports
  93  import re, sha
  94 +from MoinMoin import wikiutil
  95  
  96  Dependencies = ["page"]
  97  
  98 -def execute(macro, args):
  99 +def parse_line(line, macro, pagename):
 100 +    global result
 101 +    global baseindent
 102 +    global indent
 103 +    global titles
 104 +    global mindepth
 105 +    global maxdepth
 106 +
 107      heading = re.compile(r"^\s*(?P<hmarker>=+)\s(.*)\s(?P=hmarker)$")
 108 +    # FIXME this also finds "headlines" in {{{ code sections }}}:
 109 +    match = heading.search(line)
 110 +    if not match: return
 111 +    title_text = match.group(2)
 112 +    titles.setdefault(pagename + title_text, 0)
 113 +    titles[pagename + title_text] += 1
 114 +
 115 +    # Get new indent level
 116 +    newindent = len(match.group(1))
 117 +    if newindent > maxdepth: return
 118 +    if newindent < mindepth: return
 119 +    if not indent:
 120 +        baseindent = newindent - 1
 121 +        indent = baseindent
 122 +
 123 +    # Close lists
 124 +    for i in range(0,indent-newindent):
 125 +        result.append(macro.formatter.number_list(0))
 126 +
 127 +    # Open Lists
 128 +    for i in range(0,newindent-indent):
 129 +        result.append(macro.formatter.number_list(1))
 130 +
 131 +    # Add the heading
 132 +    unique_id = ''
 133 +    if titles[pagename + title_text] > 1:
 134 +        unique_id = '-%d' % titles[pagename + title_text]
 135 +
 136 +    result.append(macro.formatter.listitem(1))
 137 +    result.append(macro.formatter.anchorlink(
 138 +        "head-" + sha.new(pagename + title_text).hexdigest() + unique_id, title_text))
 139 +    result.append(macro.formatter.listitem(0))
 140 +    
 141 +    # Set new indent level
 142 +    indent = newindent
 143 +
 144 +def execute(macro, args):
 145 +    global result
 146 +    global baseindent
 147 +    global indent
 148 +    global titles
 149 +    global mindepth
 150 +    global maxdepth
 151 +
 152 +    include = re.compile(r"^\[\[Include\((.*)\)\]\]")
 153      result = []
 154      baseindent = 0
 155      indent = 0
 156 @@ -31,44 +84,43 @@
 157      except (ValueError, TypeError):
 158          maxdepth = 99
 159  
 160 +    pagename = macro.formatter.page.page_name
 161      for line in macro.parser.lines:
 162          # Filter out the headings
 163          lineno = lineno + 1
 164 -        # FIXME this also finds "headlines" in {{{ code sections }}}:
 165 -        match = heading.match(line)
 166 -        if not match: continue
 167 -        title_text = match.group(2)
 168 -        titles.setdefault(title_text, 0)
 169 -        titles[title_text] += 1
 170 -
 171 -        # Get new indent level
 172 -        newindent = len(match.group(1))
 173 -        if newindent > maxdepth: continue
 174 -        if newindent < mindepth: continue
 175 -        if not indent:
 176 -            baseindent = newindent - 1
 177 -            indent = baseindent
 178 -
 179 -        # Close lists
 180 -        for i in range(0,indent-newindent):
 181 -            result.append(macro.formatter.number_list(0))
 182 -
 183 -        # Open Lists
 184 -        for i in range(0,newindent-indent):
 185 -            result.append(macro.formatter.number_list(1))
 186 -
 187 -        # Add the heading
 188 -        unique_id = ''
 189 -        if titles[title_text] > 1:
 190 -            unique_id = '-%d' % titles[title_text]
 191 -
 192 -        result.append(macro.formatter.listitem(1))
 193 -        result.append(macro.formatter.anchorlink(
 194 -            "head-" + sha.new(title_text).hexdigest() + unique_id, title_text))
 195 -        result.append(macro.formatter.listitem(0))
 196 -        
 197 -        # Set new indent level
 198 -        indent = newindent
 199 +        match = include.match(line)
 200 +        if match:
 201 +            # this is an [[Include()]] line.
 202 +            # now parse the included page and do the work on it.
 203 +
 204 +            ## get heading and level from Include() line.
 205 +            args = r'^(?P<name>[^,]+),\s*(|(?P<hquote>[\'"])(?P<htext>.+?)(?P=hquote))' \
 206 +                 + r',\s*(?P<level>\d*)'
 207 +
 208 +            tmp = re.search(args, match.group(1))
 209 +            if tmp and tmp.group("name"):
 210 +                inc_pagename = tmp.group("name")
 211 +            else:
 212 +                # no pagename?  ignore it
 213 +                continue
 214 +            if tmp.group("htext"):
 215 +                heading = tmp.group("htext")
 216 +                if tmp.group("level"):
 217 +                    level = int(tmp.group("level"))
 218 +                else:
 219 +                    level = 1
 220 +                tmp_line = "%s %s %s" % ("=" * level, heading, "=" * level)
 221 +                inc_page_lines = [tmp_line]
 222 +            else:
 223 +                inc_page_lines = []
 224 +
 225 +            include_macro = wikiutil.importPlugin('macro', "Include")
 226 +            inc_page_lines = inc_page_lines \
 227 +                + include_macro(macro, match.group(1), called_by_toc=1).split("\n")
 228 +            for inc_page_line in inc_page_lines:
 229 +                parse_line(inc_page_line, macro, inc_pagename)
 230 +        else:
 231 +            parse_line(line, macro, pagename)
 232  
 233      # Close pending lists
 234      for i in range(baseindent, indent):
 235 
 236 
 237 --- orig/MoinMoin/parser/wiki.py
 238 +++ mod/MoinMoin/parser/wiki.py
 239 @@ -731,15 +731,16 @@
 240              level = level+1
 241          depth = min(5,level)
 242  
 243 +        pagename = self.formatter.page.page_name
 244          title_text = h[level:-level].strip()
 245 -        self.titles.setdefault(title_text, 0)
 246 -        self.titles[title_text] += 1
 247 +        self.titles.setdefault(pagename + title_text, 0)
 248 +        self.titles[pagename + title_text] += 1
 249  
 250          unique_id = ''
 251 -        if self.titles[title_text] > 1:
 252 -            unique_id = '-%d' % self.titles[title_text]
 253 +        if self.titles[pagename + title_text] > 1:
 254 +            unique_id = '-%d' % self.titles[pagename + title_text]
 255  
 256 -        return self.formatter.heading(depth, self.highlight_text(title_text), icons=icons, id="head-"+sha.new(title_text).hexdigest()+unique_id)
 257 +        return self.formatter.heading(depth, self.highlight_text(title_text), icons=icons, id="head-"+sha.new(pagename + title_text).hexdigest()+unique_id)
 258  
 259  
 260      def _processor_repl(self, word):

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-07-21 13:47:35, 9.0 KB) [[attachment:Include_and_TableOfContents_patch_against_280.patch]]
  • [get | view] (2004-07-21 13:48:01, 10.0 KB) [[attachment:Include_and_TableOfContents_patch_newest.patch]]
  • [get | view] (2004-07-22 14:15:43, 9.2 KB) [[attachment:Include_and_TableofContents_patch_against_1.2.3.patch]]
 All files | Selected Files: delete move to page copy to page

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