Edgewall Software
Modify

Opened 4 years ago

Closed 4 years ago

#12025 closed enhancement (fixed)

Image macro should support InterMapTxt

Reported by: anonymous Owned by: Ryan J Ollos
Priority: normal Milestone: 1.1.5
Component: wiki system Version:
Severity: normal Keywords: interwiki imagemacro
Cc:
Release Notes:

Image macro supports InterWiki prefixes.

API Changes:

Description

The image macro does not seem to support InterMapTxt prefixes. This would allow to easily extend the image macro with new capabilities e.g. for frequently linked badges, build status icons etc.)

Attachments (0)

Change History (17)

comment:1 Changed 4 years ago by anonymous

As a workaround a custom plugin can be written:

from trac.core import *
from trac.wiki.macros import WikiMacroBase
from trac.wiki.formatter import format_to_oneliner
from trac.wiki.interwiki import InterWikiMap

class SpecialImageMacro(WikiMacroBase):
    """Expands to `[[Image(SpecialImage:$1,link=SpecialImageLink:$1)]]`.
   
    Two InterMapTxt prefixes must be defined:
    {{{
    SpecialImage      http://example.com/$1.png
    SpecialImageLink  http://example.com/$1.html
    }}}
    """
    def expand_macro(self, formatter, name, content, args):
        intermap = InterWikiMap(self.env)
        src = intermap.url("SpecialImage", content)[0]
        link = intermap.url("SpecialImageLink", content)[0]
        wiki = "[[Image(%s,link=%s,title=Special Image %s)]]" % (src, link, content)
        return format_to_oneliner(self.env, formatter.context, wiki)

comment:2 Changed 4 years ago by Jun Omae

Keywords: interwiki added; intermaptxt removed

comment:3 Changed 4 years ago by Ryan J Ollos

Milestone: next-major-releases

comment:4 Changed 4 years ago by anonymous

For example with this prefix:

shields https://img.shields.io/

Wiki markup like this:

[[Image(shields:travis/edgewall/trac.svg)]]
[[Image(shields:pypi/dm/trac.svg)]]
[[Image(shields:pypi/v/trac.svg)]]

should become: https://img.shields.io/travis/edgewall/trac.svg https://img.shields.io/pypi/dm/trac.svg https://img.shields.io/pypi/v/trac.svg etc.

comment:5 Changed 4 years ago by Jun Omae

Milestone: next-major-releasesunscheduled

comment:6 Changed 4 years ago by anonymous

  • trac/wiki/macros.py

    diff -r aebe73fe2b02 trac/wiki/macros.py
    a b  
    3838from trac.wiki.formatter import (
    3939    format_to_html, format_to_oneliner, extract_link, OutlineFormatter
    4040)
     41from trac.wiki.interwiki import InterWikiMap
    4142
    4243
    4344# TODO: should be moved in .api
     
    632633                attachment = Resource(realm, id).child('attachment', filename)
    633634        elif len(parts) == 2:
    634635            realm, filename = parts
     636            interwikimap = InterWikiMap(self.env)
    635637            if realm in browser_links:  # source:path
    636638                # TODO: use context here as well
    637639                rev = None
     
    641643                raw_url = formatter.href.browser(filename, rev=rev,
    642644                                                 format='raw')
    643645                desc = filespec
     646            elif realm in interwikimap:
     647                url, desc = interwikimap.url(realm, filename)
     648                raw_url = url
    644649            else:  # #ticket:attachment or WikiPage:attachment
    645650                # FIXME: do something generic about shorthand forms...
    646651                realm = None

comment:7 Changed 4 years ago by Ryan J Ollos

Milestone: unscheduled1.1.5
Owner: set to Ryan J Ollos
Status: newassigned

Tests and documentation update were also needed. Proposed changes in log:rjollos.git:t12025.

comment:8 Changed 4 years ago by Ryan J Ollos

Keywords: imagemacro added

comment:9 Changed 4 years ago by Ryan J Ollos

Release Notes: modified (diff)

comment:10 Changed 4 years ago by Ryan J Ollos

Resolution: fixed
Status: assignedclosed

Committed to trunk in [13988].

comment:11 Changed 4 years ago by Jun Omae

I think we should respect [wiki] safe_schemes option when using InterMapTxt.

comment:12 in reply to:  11 ; Changed 4 years ago by Ryan J Ollos

Replying to jomae:

I think we should respect [wiki] safe_schemes option when using InterMapTxt.

That sounds good, but is that a change needed in ImageMacro or InterWikiMap? If the change is in InterWikiMap, we should create a new ticket.

Last edited 4 years ago by Ryan J Ollos (previous) (diff)

comment:13 in reply to:  12 Changed 4 years ago by Jun Omae

Replying to rjollos:

That sounds good, but is that a change needed in ImageMacro or InterWikiMap? If the change is in InterWikiMap, we should create a new ticket.

I've created #12053.

I noticed InterWiki allows multiple parameters. However, image macro cannot accept interwiki with multiple parameters for image. Also, the link parameter allows interwiki link with multiple parameters like this.

[[Image(/chrome/common/trac_logo_mini.png, link=gmessage:trac-users:183g75yH65w/YgJ-q8AREpwJ)]]

/chrome/common/trac_logo_mini.png

Last edited 4 years ago by Jun Omae (previous) (diff)

comment:14 Changed 4 years ago by Ryan J Ollos

Resolution: fixed
Status: closedreopened

comment:15 Changed 4 years ago by Jun Omae

Proposed changes in [b12d7d12c/jomae.git] to support interwiki link with multiple parameters in image macro.

comment:16 Changed 4 years ago by Ryan J Ollos

The changes look good to me.

comment:17 Changed 4 years ago by Jun Omae

Resolution: fixed
Status: reopenedclosed

Thanks for the reviewing. Committed in [14047].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted.
to The owner will be changed from Ryan J Ollos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.