예제 #1
0
 def invalid_args(self, elem, all_nowiki_args):
     """Insert an error message into output."""
     message = _(
         'Defaulting to plain text due to invalid arguments: "{arguments}"'
     ).format(arguments=all_nowiki_args[0])
     admonition = moin_page.div(attrib={moin_page.class_: 'error'},
                                children=[moin_page.p(children=[message])])
     elem.append(admonition)
예제 #2
0
 def __call__(self, rev, contenttype=None, arguments=None):
     try:
         item_name = rev.item.name or rev.meta['name'][0]
     except IndexError:
         # item is deleted
         message = _(
             'This deleted item must be restored before it can be viewed or downloaded, ItemID = {itemid}'
         ).format(itemid=rev.item.itemid)
         admonition = moin_page.div(
             attrib={moin_page.class_: 'error'},
             children=[moin_page.p(children=[message])])
         body = moin_page.body(children=(admonition, ))
         return moin_page.page(children=(body, ))
     attrib = {
         xlink.href:
         Iri(scheme='wiki',
             authority='',
             path='/' + item_name,
             query='do=get&rev={0}'.format(rev.revid)),
     }
     a = moin_page.a(attrib=attrib,
                     children=["Download {0}.".format(item_name)])
     body = moin_page.body(children=(a, ))
     return moin_page.page(children=(body, ))
예제 #3
0
파일: _base.py 프로젝트: suruchi4492/moin
 def __call__(self, content, arguments, page_url, alternative,
              context_block):
     ret = self.macro(content, arguments, page_url, alternative)
     if context_block:
         return moin_page.div(children=(ret, ))
     return ret
예제 #4
0
파일: rst_in.py 프로젝트: wobsta/moin
 def visit_comment(self, node):
     """
     Create moinwiki style hidden comment rather than html style: <!-- a comment -->
     """
     attrib = {moin_page.class_: 'comment dashed'}
     self.open_moin_page_node(moin_page.div(attrib=attrib))
예제 #5
0
 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
예제 #6
0
    def _Include_repl(self, args, text, context_block):
        """
        Return a moin_page node representing an include macro that will be processed
        further in /converters/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. converters/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 = str(args).replace('^',
                                     '^^').replace('(',
                                                   '^(').replace(')', '^)')
            xpointer_moin.append(function + '(' + args + ')')

        moin_args = []

        if pagename.startswith('^'):
            add_moin_xpointer('pages', pagename)
            if sort:
                add_moin_xpointer('sort', sort)
            if items:
                add_moin_xpointer('items', items)
            if skipitems:
                add_moin_xpointer('skipitems', skipitems)
        else:
            link = iri.Iri(scheme='wiki.local', path=pagename)
            attrib[xinclude.href] = link

        if heading is not None:
            add_moin_xpointer('heading', heading)
        if level:
            add_moin_xpointer('level', str(level))
        if titlesonly:
            add_moin_xpointer('titlesonly', '')
        if editlink:
            add_moin_xpointer('editlink', '')

        if xpointer_moin:
            xpointer.append('page:include({0})'.format(
                ' '.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])