Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image style attributes no longer work in 2.1.7 release #4

Closed
robnewman opened this issue Sep 11, 2013 · 6 comments
Closed

Image style attributes no longer work in 2.1.7 release #4

robnewman opened this issue Sep 11, 2013 · 6 comments

Comments

@robnewman
Copy link

In version 2.1.6 (and all previous versions) you had the ability for an image to be resized by style attributes (see lines 1243 - 1300, and especially 1271 - 1272):

def image(self, text):
        """
>>> t = Textile()
>>> t.image('!/imgs/myphoto.jpg!:http://jsamsa.com')
'<a href="http://jsamsa.com" class="img"><img src="/imgs/myphoto.jpg" alt="" /></a>'
>>> t.image('!</imgs/myphoto.jpg!')
'<img src="/imgs/myphoto.jpg" style="float: left;" alt="" />'
"""
        pattern = re.compile(r"""
(?:[\[{])? # pre
\! # opening !
(\<|\=|\>)? # optional alignment atts
(%s) # optional style,class atts
(?:\. )? # optional dot-space
([^\s(!]+) # presume this is the src
\s? # optional space
(?:\(([^\)]+)\))? # optional title
\! # closing
(?::(\S+))? # optional href
(?:[\]}]|(?=\s|$)) # lookahead: space or end of string
""" % self.c, re.U | re.X)
        return pattern.sub(self.fImage, text)

    def fImage(self, match):
        # (None, '', '/imgs/myphoto.jpg', None, None)
        align, atts, url, title, href = match.groups()
        atts = self.pba(atts)

        if align:
            atts = atts + ' style="%s"' % self.iAlign[align]

        if title:
            atts = atts + ' title="%s" alt="%s"' % (title, title)
        else:
            atts = atts + ' alt=""'

        if not self.isRelURL(url) and self.get_sizes:
            size = imagesize.getimagesize(url)
            if size:
                atts += " %s" % size

        if href:
            href = self.checkRefs(href)

        url = self.checkRefs(url)
        url = self.relURL(url)

        out = []
        if href:
            out.append('<a href="%s" class="img">' % href)
        if self.html_type == 'html':
            out.append('<img src="%s"%s>' % (url, atts))
        else:
            out.append('<img src="%s"%s />' % (url, atts))
        if href:
            out.append('</a>')

        return ''.join(out)

In version 2.1.7 you dropped some of this (lines 1327 - 1391):

def image(self, text):
        """
>>> t = Textile()
>>> t.image('!/imgs/myphoto.jpg!:http://jsamsa.com')
'<a href="http://jsamsa.com" class="img"><img alt="" src="/imgs/myphoto.jpg" /></a>'
>>> t.image('!</imgs/myphoto.jpg!')
'<img align="left" alt="" src="/imgs/myphoto.jpg" />'
"""
        pattern = re.compile(r"""
(?:[\[{])? # pre
\! # opening !
(\<|\=|\>)? # optional alignment atts
(%s) # optional style,class atts
(?:\. )? # optional dot-space
([^\s(!]+) # presume this is the src
\s? # optional space
(?:\(([^\)]+)\))? # optional title
\! # closing
(?::(\S+))? # optional href
(?:[\]}]|(?=\s|$)) # lookahead: space or end of string
""" % self.c, re.U | re.X)
        return pattern.sub(self.fImage, text)

    def fImage(self, match):
        # (None, '', '/imgs/myphoto.jpg', None, None)
        align, atts, url, title, href = match.groups()
        atts = self.pba(atts)
        size = None

        alignments = {'<': 'left', '=': 'center', '>': 'right'}

        if not title:
            title = ''

        if not self.isRelURL(url) and self.get_sizes:
            size = imagesize.getimagesize(url)

        if href:
            href = self.checkRefs(href)

        url = self.checkRefs(url)
        url = self.relURL(url)

        out = []
        if href:
            out.append('<a href="%s" class="img">' % href)
        out.append('<img')
        if align:
            out.append(' align="%s"' % alignments[align])
        out.append(' alt="%s"' % title)
        if size:
            out.append(' height="%s"' % size[1])
        out.append(' src="%s"' % url)
        if title:
            out.append(' title="%s"' % title)
        if size:
            out.append(' width="%s"' % size[0])
        if self.html_type == 'html':
            out.append('>')
        else:
            out.append(' />')
        if href:
            out.append('</a>')

        return ''.join(out)

Any reason why you did this? I recently updated to 2.1.7 and all my textile-based image styles (custom width and heights) no longer work.

@robnewman
Copy link
Author

In the meantime, rolled back to 2.1.6.

@ikirudennis
Copy link
Member

I've been meaning to look into this but haven't had time. Can you provide an example?

@adam-iris
Copy link

I think this exposes the issue:

!{height:20px;width:20px;}https://1.gravatar.com/avatar/!

ikirudennis added a commit that referenced this issue Oct 8, 2013
should fix issue #4
@ikirudennis
Copy link
Member

@robnewman, I don't know if you've seen this update. Would you be able to check it out and let me know if it's still a problem?
Thanks.

@adam-iris
Copy link

This fixes the problem in my testing. Thanks!

@robnewman
Copy link
Author

Fixes the problem in my testing too. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants