def recurse(self, elem, page): new_page_href = elem.get(moin_page.page_href) if new_page_href: page = iri.Iri(new_page_href) if elem.tag in (moin_page.part, moin_page.inline_part): yield elem, page for child in elem: if isinstance(child, ET.Node): for i in self.recurse(child, page): yield i
def create_pagelink_list(self, pagenames, ordered=False): """ creates an ET with a list of pagelinks from a list of pagenames """ page_list = moin_page.list(attrib={ moin_page.item_label_generate: ordered and 'ordered' or 'unordered' }) for pagename in pagenames: # This link can never reach pagelinks url = unicode( iri.Iri(scheme=u'wiki', authority=u'', path=u'/' + pagename)) pagelink = moin_page.a(attrib={xlink.href: url}, children=[pagename]) item_body = moin_page.list_item_body(children=[pagelink]) item = moin_page.list_item(children=[item_body]) page_list.append(item) return page_list
def _Include_repl(self, args, text, context_block): """ Return a moin_page node representing an include macro that will be processed further in /converter/include.py. The transclusion {{jpeg.jpg}} and the macro <<Include(jpeg.jpg)>> will have identical output. If context_block is true, the macro expansion will be enclosed in a DIV-tag, else the macro output will be enclosed in a SPAN-tag. converter/include.py will resolve HTML 5 validation issues should the macro output block tags within an inline context. """ def error_message(msg): txt = moin_page.p(children=(text, )) msg = moin_page.p(children=(msg, )) msg.set(moin_page.class_, 'moin-error') div = moin_page.div(children=(txt, msg)) return div if args: args = parse_arguments(args, parse_re=include_re) else: return error_message( _("Include Macro above has invalid format, missing item name")) pagename = args[0] heading = None level = None try: heading = args[1] level = int(args[2]) except (IndexError, ValueError): pass sort = 'sort' in args and args['sort'] if sort and sort not in ('ascending', 'descending'): return error_message( _("Include Macro above has invalid format, expected sort=ascending or descending" )) # TODO: We need corresponding code in include.py to process items, skipitems, titlesonly, and editlink items = 'items' in args and int(args['items']) skipitems = 'skipitems' in args and int(args['skipitems']) titlesonly = 'titlesonly' in args editlink = 'editlink' in args attrib = {} xpointer = [] xpointer_moin = [] def add_moin_xpointer(function, args): args = unicode(args).replace('^', '^^').replace('(', '^(').replace( ')', '^)') xpointer_moin.append(function + u'(' + args + u')') moin_args = [] if pagename.startswith(u'^'): add_moin_xpointer(u'pages', pagename) if sort: add_moin_xpointer(u'sort', sort) if items: add_moin_xpointer(u'items', items) if skipitems: add_moin_xpointer(u'skipitems', skipitems) else: link = iri.Iri(scheme=u'wiki.local', path=pagename) attrib[xinclude.href] = link if heading is not None: add_moin_xpointer(u'heading', heading) if level: add_moin_xpointer(u'level', str(level)) if titlesonly: add_moin_xpointer(u'titlesonly', u'') if editlink: add_moin_xpointer(u'editlink', u'') if xpointer_moin: xpointer.append(u'page:include({0})'.format( u' '.join(xpointer_moin))) if xpointer: # TODO: Namespace? ns = 'xmlns(page={0}) '.format(moin_page) attrib[xinclude.xpointer] = ns + ' '.join(xpointer) span_wrap = xinclude.include(attrib=attrib) if not context_block: return span_wrap attrib = {moin_page.class_: 'moin-p'} return moin_page.div(attrib=attrib, children=[span_wrap])