Edgewall Software

Ticket #739 (closed enhancement: fixed)

Opened 4 years ago

Last modified 3 years ago

Enhance inline image handling

Reported by: daniel+trac@… Owned by: cboos
Priority: normal Milestone: 0.9
Component: wiki system Version: devel
Severity: normal Keywords:
Cc: daniel+trac@…

Description

It would be nice if the Trac wiki would support ways to:

  • Inline attached images via straightforward syntax
  • Inline images by relative URIs, without leading http:
  • Force the inlining of images with arbitrary URLs, not necessarily beginning with http: and not necessarily ending in .png, .jpg, .gif

without falling back to inline HTML and WikiProcessors magic.

Possible syntax could be:

PageName/attached-image.png or PageName:attached-image.png
image:relative/path/to/image.png
image:/uri/to/image.png
image:http://foo.com/image.bmp
image:/cgi-bin/generated-image.cgi

Also compare with #691 where a similar issue is raised for hyperlinks, with solutions partially covering some of the above cases in a different way.

Attachments

Change History

Changed 4 years ago by tstivers@…

The patches I made for #691 will auto-inline relative links to images but won't handle cgi generated images (it inlines using extensions just like http:// links). I'd like to see some way of doing relative links, including links to images included in the 0.8 release if at all possible. It would also be nice to reference attachments as attachment:filename.ext and [attachment:filename.ext fancyname] with auto image inlining based on extension.

Changed 4 years ago by daniel

  • milestone set to 0.9

Changed 4 years ago by Steven N. Severinghaus <sns@…>

For what it's worth, I've made a minor change to source:/file/trunk/trac/WikiFormatter.py that allows us to put images inside links, e.g. [http://foo/bar.jpg http://foo/bar_thumb.jpg] could be used to create a thumbnail link. The complete source of the relevant function is below. I can supply a diff if desired, but the change is fairly obvious and localized to the last few lines.

    def _fancylink_formatter(self, match, fullmatch):
        link = fullmatch.group('fancyurl')
        name = fullmatch.group('linkname')

        module_link, t, missing, title = self._expand_module_link(link)
        if module_link and missing:
            return '<a class="missing" href="%s">%s?</a>' % (module_link, name)
        elif module_link:
            return '<a href="%s">%s</a>' % (module_link, name)
        elif name.endswith('.png') or name.endswith('.jpg') or name.endswith('.gif'):
            return '<a href="%s"><img src="%s" alt="%s" /></a>' % (link, name, name)
        else:
            return '<a class="ext-link" title="%s" href="%s">%s</a>' % (link, link, name)

An example of this in action can be found here.

Changed 3 years ago by cboos

  • owner changed from jonas to cboos
  • status changed from new to assigned

I'll try to integrate the Image macro from Shun-ichi Goto.

Changed 3 years ago by cboos

  • status changed from assigned to closed
  • resolution set to fixed

Seems to work fine. Fixed in [1872] (source:trunk/wiki-macros/Image.py#latest)

An environment upgrade is needed for installing the new macro (see [1871]).

Changed 3 years ago by cmlenz

cboos, I don't quite understand why you implemented this as a "classic" user macro. Why not put it, together with the other core macros, in trac.wiki.macros? I really think this functionality is important/essential enough to be put in the core.

Changed 3 years ago by cboos

Well, ok, I'll do it tomorrow.

At least it helped me to discover a few issues with user macros :)

Changed 3 years ago by cboos

Hm, I think it would be better to leave this big macro in its own file:

The other default macros source:trunk/trac/wiki/macros.py could then either go in

or be split up:

Besides being default macros, those macros are quite unrelated to each other, so I think splitting them up is better.

Changed 3 years ago by cmlenz

Why? I just don't see the problem here.

Add/Change #739 (Enhance inline image handling)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
to The owner will change from cboos. Next status will be 'closed'
 
Note: See TracTickets for help on using tickets.