Пример #1
0
    def _url_repl(self, word):
        """Handle literal URLs including inline images."""
        scheme = word.split(":", 1)[0]

        attrs = {}

        # Handle literal URLs to local resources using a special 'file' scheme. This allows
        # to insert local images without using brackets and making them a link to themselfes
        # as a side effect.
        if scheme == 'file':
            # file:///image.gif -> image.gif
            word = word[7:].split('/', 1)[-1]
            text = wikiutil.url_unquote(os.path.basename(word))
        else:
            text = word
            if config.general.targetblank:
                attrs = dict(target='_blank')

        # CSS class split
        schsep = word.split('|')
        word = schsep[0]
        if len(schsep) > 1:
            scheme = '%s %s' % (scheme, ' '.join(schsep[1:]))

        if wikiutil.isPicture(word):
            # Get image name http://here.com/dir/image.gif -> image
            name = wikiutil.url_unquote(os.path.splitext(os.path.basename(word))[0])
            return self.formatter.image(src=word, alt=name, css=scheme)
        else:
            return (self.formatter.url(1, word, css=scheme, **attrs) +
                    self.formatter.text(text) +
                    self.formatter.url(0))
Пример #2
0
    def _url_repl(self, word):
        """Handle literal URLs including inline images."""
        scheme = word.split(":", 1)[0]

        attrs = {}

        # Handle literal URLs to local resources using a special 'file' scheme. This allows
        # to insert local images without using brackets and making them a link to themselfes
        # as a side effect.
        if scheme == 'file':
            # file:///image.gif -> image.gif
            word = word[7:].split('/', 1)[-1]
            text = wikiutil.url_unquote(os.path.basename(word))
        else:
            text = word
            if config.general.targetblank:
                attrs = dict(target='_blank')

        # CSS class split
        schsep = word.split('|')
        word = schsep[0]
        if len(schsep) > 1:
            scheme = '%s %s' % (scheme, ' '.join(schsep[1:]))

        if wikiutil.isPicture(word):
            # Get image name http://here.com/dir/image.gif -> image
            name = wikiutil.url_unquote(
                os.path.splitext(os.path.basename(word))[0])
            return self.formatter.image(src=word, alt=name, css=scheme)
        else:
            return (self.formatter.url(1, word, css=scheme, **attrs) +
                    self.formatter.text(text) + self.formatter.url(0))
Пример #3
0
    def url(self, on, url=None, css=None, do_escape=0, **kw):
        """
        Inserts an <a> element.

        Call once with on=1 to start the link, and again with on=0
        to end it (no other arguments are needed when on==0).

        do_escape: XXX doesn't work yet

        Keyword params:
            url - the URL to link to; will go through Wiki URL mapping.
            css - a space-separated list of CSS classes
            attrs -  just include this string verbatim inside
                     the <a> element; can be used for arbitrary attrs;
                     all escaping and quoting is the caller's responsibility.

        Note that the 'attrs' keyword argument is for backwards compatibility
        only.  It should not be used for new code -- instead just pass
        any attributes in as separate keyword arguments.

        1.5.3: removed ugly "attrs" keyword argument handling code
        """
        if on:
            attrs = {}

            # Handle the URL mapping
            if url is None and kw.has_key('href'):
                url = kw['href']
                del kw['href']
            if url is not None:
                #url = wikiutil.mapURL(self.request, url)
                # TODO just calling url_quote does not work, as it will also quote "http:" to "http%xx" X)
                if 0:  # do_escape: # protocol and server part must not get quoted, path should get quoted
                    url = wikiutil.url_quote(url)
                attrs['href'] = url

                # Warn about non-existing local files.
                if url[:16].find('://') < 0:
                    name = wikiutil.url_unquote(url.split('#', 1)[0])
                    if name and not os.path.exists(name):
                        warning('linked "%s" file does not exists' % name)

            if css:
                attrs['class'] = css

            markup = self._open('a', attr=attrs, **kw)
        else:
            markup = self._close('a')
        return markup
Пример #4
0
    def url(self, on, url=None, css=None, do_escape=0, **kw):
        """
        Inserts an <a> element.

        Call once with on=1 to start the link, and again with on=0
        to end it (no other arguments are needed when on==0).

        do_escape: XXX doesn't work yet

        Keyword params:
            url - the URL to link to; will go through Wiki URL mapping.
            css - a space-separated list of CSS classes
            attrs -  just include this string verbatim inside
                     the <a> element; can be used for arbitrary attrs;
                     all escaping and quoting is the caller's responsibility.

        Note that the 'attrs' keyword argument is for backwards compatibility
        only.  It should not be used for new code -- instead just pass
        any attributes in as separate keyword arguments.

        1.5.3: removed ugly "attrs" keyword argument handling code
        """
        if on:
            attrs = {}

            # Handle the URL mapping
            if url is None and kw.has_key('href'):
                url = kw['href']
                del kw['href']
            if url is not None:
                #url = wikiutil.mapURL(self.request, url)
                # TODO just calling url_quote does not work, as it will also quote "http:" to "http%xx" X)
                if 0: # do_escape: # protocol and server part must not get quoted, path should get quoted
                    url = wikiutil.url_quote(url)
                attrs['href'] = url
                
                # Warn about non-existing local files.
                if url[:16].find('://') < 0:
                    name = wikiutil.url_unquote(url.split('#', 1)[0])
                    if name and not os.path.exists(name):
                        warning('linked "%s" file does not exists' % name)

            if css:
                attrs['class'] = css
            
            markup = self._open('a', attr=attrs, **kw)
        else:
            markup = self._close('a')
        return markup
Пример #5
0
    def image(self, src=None, css=None, **kw):
        """Creates an inline image with an <img> element.

        The src argument must be the URL to the image file.
        """
        if src:
            kw['src'] = src

            if css:
                kw['class'] = css

            if src[:16].find('://') < 0:
                name = wikiutil.url_unquote(src)
                if not os.path.exists(name):
                    warning('"%s" image does not exists' % name)

        return self._open('img', **kw)
Пример #6
0
    def image(self, src=None, css=None, **kw):
        """Creates an inline image with an <img> element.

        The src argument must be the URL to the image file.
        """
        if src:
            kw['src'] = src
            
            if css:
                kw['class'] = css
            
            if src[:16].find('://') < 0:
                name = wikiutil.url_unquote(src)
                if not os.path.exists(name):
                    warning('"%s" image does not exists' % name)

        return self._open('img', **kw)