예제 #1
0
파일: creole_in.py 프로젝트: moinwiki/moin
 def inline_object_repl(self,
                        stack,
                        object,
                        object_page=None,
                        object_url=None,
                        object_text=None):
     """Handles objects included in the page."""
     attrib = {}
     if object_text:
         attrib[html.alt] = object_text
     if object_page is not None:
         att = 'attachment:'  # moin 1.9 needed this for an attached file
         if object_page.startswith(att):
             object_page = '/' + object_page[len(
                 att):]  # now we have a subitem
         target = Iri(scheme='wiki.local', path=object_page)
         attrib[xinclude.href] = target
         element = xinclude.include(attrib=attrib)
     else:
         attrib[xlink.href] = object_url
         element = moin_page.object(
             attrib=attrib,
             children=(
                 'Your Browser does not support HTML5 audio/video element.',
             ))
     stack.top_append(element)
예제 #2
0
    def inline_object_repl(self, stack, object, object_url=None, object_item=None,
                           object_text=None, object_args=None):
        """Handles objects transcluded within the page."""
        if object_args:
            args = parse_arguments(object_args).keyword  # XXX needs different parsing
        else:
            args = {}

        query_keys = {}
        attrib = {}
        whitelist = ['width', 'height', 'class']
        for attr, value in args.items():
            if attr.startswith('&'):
                query_keys[attr[1:]] = value
            elif attr in whitelist:
                attrib[html(attr)] = value
        if object_text:
            attrib[html.alt] = object_text
        if object_item is not None:
            # img tag
            query = url_encode(query_keys, charset=CHARSET, encode_keys=True)
            # TODO: moin 1.9 needed this for an attached file; move functionality to scripts/migration/moin/import19.py
            att = 'attachment:'
            if object_item.startswith(att):
                object_item = '/' + object_item[len(att):]  # now we have a subitem
            target = Iri(scheme='wiki.local', path=object_item, query=query, fragment=None)
            attrib[xinclude.href] = target
            element = xinclude.include(attrib=attrib)
            stack.top_append(element)
        else:
            # object tag
            target = Iri(object_url)
            attrib[xlink.href] = target
            element = moin_page.object(attrib)
            stack.top_append(element)
예제 #3
0
파일: html_in.py 프로젝트: suruchi4492/moin
 def visit_xhtml_img(self, element):
     """
     <img src="URI" /> --> <object xlink:href="URI />
     """
     key = xlink('href')
     attrib = self.convert_attributes(element)
     # adding type_ attrib makes html_out create an image tag rather than an object tag
     attrib[moin_page.type_] = 'image/'
     if self.base_url:
         attrib[key] = ''.join([self.base_url, element.get(html.src)])
     else:
         attrib[key] = element.get(html.src)
     return moin_page.object(attrib)
예제 #4
0
파일: html_in.py 프로젝트: suruchi4492/moin
    def visit_xhtml_object(self, element):
        """
        <object data="href"></object> --> <object xlink="href" />
        """
        key = xlink('href')
        attrib = {}
        if self.base_url:
            attrib[key] = ''.join([self.base_url, element.get(html.data)])
        else:
            attrib[key] = element.get(html.data)

        # Convert the href attribute into unicode
        attrib[key] = str(attrib[key])
        return moin_page.object(attrib)
예제 #5
0
    def visit_image(self, node):
        """
        Processes images and other transcluded objects.
        """
        whitelist = [
            'width',
            'height',
            'alt',
        ]
        attrib = {}
        for key in whitelist:
            if node.get(key):
                attrib[html(key)] = node.get(key)

        # there is no 'scale' attribute, hence absent from whitelist, handled separately
        if node.get('scale'):
            scaling_factor = int(node.get('scale')) / 100.0
            for key in ('width', 'height'):
                if html(key) in attrib:
                    attrib[html(key)] = int(
                        int(attrib[html(key)]) * scaling_factor)

        # "align" parameter is invalid in HTML5. Convert it to a class defined in userstyles.css.
        userstyles = {
            'left': 'left',
            'center': 'center',
            'right': 'right',
            'top':
            'top',  # rst parser creates error messages for top, bottom, and middle
            'bottom': 'bottom',
            'middle': 'middle',
        }
        alignment = userstyles.get(node.get('align'))
        if alignment:
            attrib[html.class_] = alignment

        url = Iri(node['uri'])
        if url.scheme is None:
            # img
            target = Iri(scheme='wiki.local', path=node['uri'], fragment=None)
            attrib[xinclude.href] = target
            new_node = xinclude.include(attrib=attrib)
        else:
            # obj
            new_node = moin_page.object(attrib)
            new_node.set(xlink.href, url)

        self.open_moin_page_node(new_node)
예제 #6
0
 def visit_img(self, element):
     """
     <img src="URI" /> --> <object xlink:href="URI />
     """
     attrib = {}
     url = Iri(element.attrib.get('src'))
     if element.attrib.get('alt'):
         attrib[html.alt] = element.attrib.get('alt')
     if element.attrib.get('title'):
         attrib[html.title_] = element.attrib.get('title')
     if url.scheme is None:
         # img tag
         target = Iri(scheme='wiki.local', path=element.attrib.get("src"), fragment=None)
         attrib[xinclude.href] = target
         new_node = xinclude.include(attrib=attrib)
     else:
         # object tag
         attrib[xlink.href] = url
         new_node = moin_page.object(attrib)
     return new_node
예제 #7
0
파일: mediawiki_in.py 프로젝트: wobsta/moin
    def inline_link_repl(self,
                         stack,
                         link,
                         link_url=None,
                         link_item=None,
                         link_args=u'',
                         external_link_url=None,
                         alt_text=u''):
        """Handle all kinds of links."""
        link_text = ''
        link_args_list = []
        # Remove the first pipe/space, example of link_args : |arg1|arg2 or " arg1 arg2"
        parsed_args = self.parse_args(link_args[1:])
        query = None
        if parsed_args.keyword:
            query = url_encode(parsed_args.keyword,
                               charset=CHARSET,
                               encode_keys=True,
                               sort=True)
        # Take the last of positional parameters as link_text(caption)
        if parsed_args.positional:
            link_text = parsed_args.positional.pop()
        if link_item is not None:
            if '#' in link_item:
                path, fragment = link_item.rsplit('#', 1)
            else:
                path, fragment = link_item, None
            target = Iri(scheme='wiki.local',
                         path=path,
                         query=query,
                         fragment=fragment)
            text = link_item
        else:
            if link_url and len(link_url.split(':')) > 0 and link_url.split(
                    ':')[0] == 'File':
                object_item = ':'.join(link_url.split(':')[1:])
                args = parsed_args.keyword
                if object_item is not None:
                    if 'do' not in args:
                        # by default, we want the item's get url for transclusion of raw data:
                        args['do'] = 'get'
                    query = url_encode(args,
                                       charset=CHARSET,
                                       encode_keys=True,
                                       sort=True)
                    target = Iri(scheme='wiki.local',
                                 path=object_item,
                                 query=query,
                                 fragment=None)
                    text = object_item
                else:
                    target = Iri(scheme='wiki.local', path=link_url)
                    text = link_url

                if not link_text:
                    link_text = text
                attrib = {xlink.href: target}
                attrib[moin_page.alt] = link_text

                element = moin_page.object(attrib)
                stack.push(element)
                if link_text:
                    self.preprocessor.push()
                    self.parse_inline(link_text, stack, self.inlinedesc_re)
                    self.preprocessor.pop()
                else:
                    stack.top_append(text)
                stack.pop()
                return
            target = Iri(scheme='wiki.local', path=link_url)
            text = link_url
        if external_link_url:
            target = Iri(external_link_url)
            text = alt_text
        element = moin_page.a(attrib={xlink.href: target})
        stack.push(element)
        if link_text:
            self.preprocessor.push()
            self.parse_inline(link_text, stack, self.inlinedesc_re)
            self.preprocessor.pop()
        else:
            stack.top_append(text)
        stack.pop()