Attachment 'Include_and_TableofContents_patch_against_1.2.3.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,104 @@
  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 process_lines(macro, lines, pagename):
 145 +    global lineno
 146 +    global include
 147 +    for line in lines:
 148 +        # Filter out the headings
 149 +        lineno = lineno + 1
 150 +        match = include.match(line)
 151 +        if match:
 152 +            # this is an [[Include()]] line.
 153 +            # now parse the included page and do the work on it.
 154 +
 155 +            ## get heading and level from Include() line.
 156 +            args = r'^(?P<name>[^,]+),?(?:\s*(?:(?P<hquote>[\'"])(?P<htext>.+?)(?P=hquote))?,?(?:\s*(?P<level>\d*))?)?'
 157 +
 158 +            tmp = re.search(args, match.group(1))
 159 +            if tmp and tmp.group("name"):
 160 +                inc_pagename = tmp.group("name")
 161 +            else:
 162 +                # no pagename?  ignore it
 163 +                continue
 164 +            if tmp.group("htext"):
 165 +                heading = tmp.group("htext")
 166 +                if tmp.group("level"):
 167 +                    level = int(tmp.group("level"))
 168 +                else:
 169 +                    level = 1
 170 +                tmp_line = "%s %s %s" % ("=" * level, heading, "=" * level)
 171 +                inc_page_lines = [tmp_line]
 172 +            else:
 173 +                inc_page_lines = []
 174 +
 175 +            include_macro = wikiutil.importPlugin('macro', "Include")
 176 +            inc_page_lines = inc_page_lines \
 177 +                + include_macro(macro, match.group(1), called_by_toc=1).split("\n")
 178 +            process_lines(macro, inc_page_lines, inc_pagename)
 179 +        else:
 180 +            parse_line(line, macro, pagename)
 181 +
 182 +def execute(macro, args):
 183 +    global result
 184 +    global baseindent
 185 +    global indent
 186 +    global titles
 187 +    global mindepth
 188 +    global maxdepth
 189 +    global lineno
 190 +    global include
 191 +
 192 +    include = re.compile(r"^\[\[Include\((.*)\)\]\]")
 193      result = []
 194      baseindent = 0
 195      indent = 0
 196 @@ -31,44 +124,8 @@
 197      except (ValueError, TypeError):
 198          maxdepth = 99
 199  
 200 -    for line in macro.parser.lines:
 201 -        # Filter out the headings
 202 -        lineno = lineno + 1
 203 -        # FIXME this also finds "headlines" in {{{ code sections }}}:
 204 -        match = heading.match(line)
 205 -        if not match: continue
 206 -        title_text = match.group(2)
 207 -        titles.setdefault(title_text, 0)
 208 -        titles[title_text] += 1
 209 -
 210 -        # Get new indent level
 211 -        newindent = len(match.group(1))
 212 -        if newindent > maxdepth: continue
 213 -        if newindent < mindepth: continue
 214 -        if not indent:
 215 -            baseindent = newindent - 1
 216 -            indent = baseindent
 217 -
 218 -        # Close lists
 219 -        for i in range(0,indent-newindent):
 220 -            result.append(macro.formatter.number_list(0))
 221 -
 222 -        # Open Lists
 223 -        for i in range(0,newindent-indent):
 224 -            result.append(macro.formatter.number_list(1))
 225 -
 226 -        # Add the heading
 227 -        unique_id = ''
 228 -        if titles[title_text] > 1:
 229 -            unique_id = '-%d' % titles[title_text]
 230 -
 231 -        result.append(macro.formatter.listitem(1))
 232 -        result.append(macro.formatter.anchorlink(
 233 -            "head-" + sha.new(title_text).hexdigest() + unique_id, title_text))
 234 -        result.append(macro.formatter.listitem(0))
 235 -        
 236 -        # Set new indent level
 237 -        indent = newindent
 238 +    pagename = macro.formatter.page.page_name
 239 +    process_lines(macro, macro.parser.lines, pagename)
 240  
 241      # Close pending lists
 242      for i in range(baseindent, indent):
 243 
 244 
 245 --- orig/MoinMoin/parser/wiki.py
 246 +++ mod/MoinMoin/parser/wiki.py
 247 @@ -737,15 +737,16 @@
 248              level = level+1
 249          depth = min(5,level)
 250  
 251 +        pagename = self.formatter.page.page_name
 252          title_text = h[level:-level].strip()
 253 -        self.titles.setdefault(title_text, 0)
 254 -        self.titles[title_text] += 1
 255 +        self.titles.setdefault(pagename + title_text, 0)
 256 +        self.titles[pagename + title_text] += 1
 257  
 258          unique_id = ''
 259 -        if self.titles[title_text] > 1:
 260 -            unique_id = '-%d' % self.titles[title_text]
 261 +        if self.titles[pagename + title_text] > 1:
 262 +            unique_id = '-%d' % self.titles[pagename + title_text]
 263  
 264 -        return self.formatter.heading(depth, self.highlight_text(title_text), icons=icons, id="head-"+sha.new(title_text).hexdigest()+unique_id)
 265 +        return self.formatter.heading(depth, self.highlight_text(title_text), icons=icons, id="head-"+sha.new(pagename + title_text).hexdigest()+unique_id)
 266  
 267  
 268      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.