Attachment 'Include_and_TableOfContents_patch_newest.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,105 @@
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))' \
157 + + r',\s*(?P<level>\d*)'
158 +
159 + tmp = re.search(args, match.group(1))
160 + if tmp and tmp.group("name"):
161 + inc_pagename = tmp.group("name")
162 + else:
163 + # no pagename? ignore it
164 + continue
165 + if tmp.group("htext"):
166 + heading = tmp.group("htext")
167 + if tmp.group("level"):
168 + level = int(tmp.group("level"))
169 + else:
170 + level = 1
171 + tmp_line = "%s %s %s" % ("=" * level, heading, "=" * level)
172 + inc_page_lines = [tmp_line]
173 + else:
174 + inc_page_lines = []
175 +
176 + include_macro = wikiutil.importPlugin('macro', "Include")
177 + inc_page_lines = inc_page_lines \
178 + + include_macro(macro, match.group(1), called_by_toc=1).split("\n")
179 + process_lines(macro, inc_page_lines, inc_pagename)
180 + else:
181 + parse_line(line, macro, pagename)
182 +
183 +def execute(macro, args):
184 + global result
185 + global baseindent
186 + global indent
187 + global titles
188 + global mindepth
189 + global maxdepth
190 + global lineno
191 + global include
192 +
193 + include = re.compile(r"^\[\[Include\((.*)\)\]\]")
194 result = []
195 baseindent = 0
196 indent = 0
197 @@ -31,44 +125,8 @@
198 except (ValueError, TypeError):
199 maxdepth = 99
200
201 - for line in macro.parser.lines:
202 - # Filter out the headings
203 - lineno = lineno + 1
204 - # FIXME this also finds "headlines" in {{{ code sections }}}:
205 - match = heading.match(line)
206 - if not match: continue
207 - title_text = match.group(2)
208 - titles.setdefault(title_text, 0)
209 - titles[title_text] += 1
210 -
211 - # Get new indent level
212 - newindent = len(match.group(1))
213 - if newindent > maxdepth: continue
214 - if newindent < mindepth: continue
215 - if not indent:
216 - baseindent = newindent - 1
217 - indent = baseindent
218 -
219 - # Close lists
220 - for i in range(0,indent-newindent):
221 - result.append(macro.formatter.number_list(0))
222 -
223 - # Open Lists
224 - for i in range(0,newindent-indent):
225 - result.append(macro.formatter.number_list(1))
226 -
227 - # Add the heading
228 - unique_id = ''
229 - if titles[title_text] > 1:
230 - unique_id = '-%d' % titles[title_text]
231 -
232 - result.append(macro.formatter.listitem(1))
233 - result.append(macro.formatter.anchorlink(
234 - "head-" + sha.new(title_text).hexdigest() + unique_id, title_text))
235 - result.append(macro.formatter.listitem(0))
236 -
237 - # Set new indent level
238 - indent = newindent
239 + pagename = macro.formatter.page.page_name
240 + process_lines(macro, macro.parser.lines, pagename)
241
242 # Close pending lists
243 for i in range(baseindent, indent):
244
245
246 --- orig/MoinMoin/parser/wiki.py
247 +++ mod/MoinMoin/parser/wiki.py
248 @@ -510,6 +510,21 @@
249 # Close open paragraphs and list items
250 if self._indent_level() != new_level:
251 self._close_item(close)
252 + else:
253 + # don't want the raw text:
254 + # 1. bullet item
255 + # This line should
256 + # be in one line.
257 + # to be viewd:
258 + # 1. bullet item
259 + # This line should
260 + #
261 + # be in one line.
262 + # of course, it should be:
263 + # 1. bullet item
264 + # This line should be in one line.
265 + if not self.line_was_empty:
266 + self.inhibit_p = 1
267
268 # Close lists while char-wise indent is greater than the current one
269 while self._indent_level() > new_level:
270 @@ -731,15 +746,16 @@
271 level = level+1
272 depth = min(5,level)
273
274 + pagename = self.formatter.page.page_name
275 title_text = h[level:-level].strip()
276 - self.titles.setdefault(title_text, 0)
277 - self.titles[title_text] += 1
278 + self.titles.setdefault(pagename + title_text, 0)
279 + self.titles[pagename + title_text] += 1
280
281 unique_id = ''
282 - if self.titles[title_text] > 1:
283 - unique_id = '-%d' % self.titles[title_text]
284 + if self.titles[pagename + title_text] > 1:
285 + unique_id = '-%d' % self.titles[pagename + title_text]
286
287 - return self.formatter.heading(depth, self.highlight_text(title_text), icons=icons, id="head-"+sha.new(title_text).hexdigest()+unique_id)
288 + return self.formatter.heading(depth, self.highlight_text(title_text), icons=icons, id="head-"+sha.new(pagename + title_text).hexdigest()+unique_id)
289
290
291 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.You are not allowed to attach a file to this page.