This is a small patch against Include.py that allows the 'level' argument to be negative. When a negative level argument is supplied, the level of titles in the included document is reduced by the specified amount. For example, given {{{[[Include(MyPage, ,-1)]]}}} a title like {{{= Title =}}} will be changed to {{{== Title ==}}}, {{{== Sub Title ==}}} will become {{{=== Sub Title ===}}} and so on. {{{ --- Include.py.orig 2007-09-25 08:12:43.000000000 +1000 +++ /usr/local/moin/lib/python2.4/site-packages/MoinMoin/macro/Include.py 2007-09-25 08:46:29.000000000 +1000 @@ -25,7 +25,7 @@ ## keep in sync with TableOfContents macro! _arg_heading = r'(?P,)\s*(|(?P[\'"])(?P.+?)(?P=hquote))' -_arg_level = r',\s*(?P\d*)' +_arg_level = r',\s*(?P-?\d*)' _arg_from = r'(,\s*from=(?P[\'"])(?P.+?)(?P=fquote))?' _arg_to = r'(,\s*to=(?P[\'"])(?P.+?)(?P=tquote))?' _arg_sort = r'(,\s*sort=(?P(ascending|descending)))?' @@ -50,6 +50,25 @@ titles.append((title_text, level)) return titles +def shrink_titles(body, amount, title_re): + position = 0 + for title, _ in title_re.findall(body): + h = title.strip() + level = 1 + while h[level:level+1] == '=': level = level+1 + depth = min(5,level+amount) + + position = body.find(h, position) + newh = h + while level < depth: + newh = '=' + newh + '=' + level += 1 + + body = body[0:position] + newh + body[position+len(h):] + position += len(newh) + + return body + def execute(macro, text, args_re=re.compile(_args_re_pattern), title_re=re.compile(_title_re, re.M), called_by_toc=0): request = macro.request _ = request.getText @@ -112,6 +131,12 @@ inc_page = Page(request, inc_name, formatter=fmt) inc_page._macroInclude_pagelist = this_page._macroInclude_pagelist + # If level is negative, reduce the size of included titles by that amount + if args.group('level') and int(args.group('level')) < 0: + body = shrink_titles(inc_page.get_raw_body(), abs(int(args.group('level'))), title_re) + inc_page.set_raw_body(body, modified=True) + + # check for "from" and "to" arguments (allowing partial includes) body = inc_page.get_raw_body() + '\n' from_pos = 0 }}} Great patch, thanks! Please include in the default Include.py!