Esempio n. 1
0
 def inline_comment_repl(self, stack, comment, comment_begin=None, comment_end=None):
     if comment_begin:
         attrib = {moin_page('class'): 'comment'}
         elem = moin_page.span(attrib=attrib)
         stack.push(elem)
     else:
         stack.pop()
Esempio n. 2
0
 def depart_term(self, node):
     # classifiers arrive as siblings of the term; search the parent and convert them to children
     for child in node.parent:
         if isinstance(child, docutils.nodes.classifier):
             classifier = u":" + child[0]
             self.open_moin_page_node(moin_page.span(children=[classifier]))
             self.close_moin_page_node()
     self.close_moin_page_node()
Esempio n. 3
0
 def inline_size_repl(self, stack, size, size_begin=None, size_end=None):
     if size_begin:
         size = '120%' if size[1] == '+' else '85%'
         attrib = {moin_page.font_size: size}
         elem = moin_page.span(attrib=attrib)
         stack.push(elem)
     else:
         stack.pop()
Esempio n. 4
0
    def visit_target(self, node):
        """
        Pass explicit anchor as a SPAN with no children, just an ID attribute

        .. _example:
        """
        anchor = node.get('refid')
        if anchor:
            self.open_moin_page_node(moin_page.span(attrib={moin_page.id: anchor}))
            self.close_moin_page_node()
Esempio n. 5
0
    def macro(self, content, arguments, page_url, alternative):
        if arguments:
            item_count = int(arguments[0])
        else:
            item_count = 1

        all_item_names = self.get_item_names()

        # Now select random item from the full list, and if it exists and
        # we can read it, save.
        random_item_names = []
        found = 0
        while found < item_count and all_item_names:
            # Take one random item from the list
            item_name = random.choice(all_item_names)
            all_item_names.remove(item_name)

            # Filter out items the user may not read.
            try:
                item = Item.create(item_name)
                random_item_names.append(item_name)
                found += 1
            except AccessDenied:
                pass

        if not random_item_names:
            return

        random_item_names.sort()

        result = moin_page.span()
        for name in random_item_names:
            link = unicode(Iri(scheme=u'wiki', authority=u'',
                               path=u'/' + name))
            result.append(
                moin_page.a(attrib={xlink.href: link}, children=[name]))
            result.append(", ")

        del result[-1]  # kill last comma
        return result
Esempio n. 6
0
    def macro(self, content, arguments, page_url, alternative):
        args = arguments[0] if arguments else ""
        if not args:
            raise ValueError("Missing font name")
        args = args.split(',')
        fonts = args[0].split()
        color = args[1].strip() if len(args) > 1 else ""
        size = args[2].strip() if len(args) > 2 else ""

        if color.startswith('#'):
            try:
                int(color[1:], 16)
                assert len(color) in (4, 7)
                color = 'color: {0}; '.format(color)
            except (ValueError, AssertionError):
                color = ""

        if size:
            try:
                s = float(size)
                assert s > 0.1
                assert s < 99
                size = 'font-size: {0}em;'.format(size)
            except (ValueError, AssertionError):
                size = ""

        style = color + size
        classes = []
        for font in fonts:
            f = font if font.startswith('fa-') or font == 'fa' else 'fa-' + font
            classes.append(f)
        if 'fa' not in classes:
            classes.insert(0, 'fa')
        classes = ' '.join(classes)

        attrib = {moin_page.class_: classes}
        if style:
            attrib[moin_page.style] = style
        return moin_page.span(attrib=attrib)
Esempio n. 7
0
 def visit_superscript(self, node):
     self.open_moin_page_node(
         moin_page.span(
             attrib={moin_page.baseline_shift: u'super'}))
Esempio n. 8
0
 def inline_superscript_repl(self, stack, superscript, superscript_text):
     attrib = {moin_page.baseline_shift: 'super'}
     elem = moin_page.span(attrib=attrib, children=[superscript_text])
     stack.top_append(elem)
Esempio n. 9
0
 def _append(self, type, value, element):
     class_ = STANDARD_TYPES.get(type)
     if class_:
         value = moin_page.span(attrib={moin_page.class_: class_}, children=(value, ))
     element.append(value)
Esempio n. 10
0
    def macro(self, content, arguments, page_url, alternative):
        if not arguments:
            raise ValueError("Anchor: you need to specify an anchor name.")

        anchor = arguments[0]
        return moin_page.span(attrib={moin_page.id: anchor})