Edgewall Software

Opened 9 years ago

Last modified 9 years ago

#12025 closed enhancement

Image macro should support InterMapTxt — at Version 9

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

Image macro supports InterWiki prefixes.

API Changes:
Internal 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.)

Change History (9)

comment:1 by anonymous, 9 years ago

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 by Jun Omae, 9 years ago

Keywords: interwiki added; intermaptxt removed

comment:3 by Ryan J Ollos, 9 years ago

Milestone: next-major-releases

comment:4 by anonymous, 9 years ago

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 by Jun Omae, 9 years ago

Milestone: next-major-releasesunscheduled

comment:6 by anonymous, 9 years ago

  • 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 by Ryan J Ollos, 9 years ago

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 by Ryan J Ollos, 9 years ago

Keywords: imagemacro added

comment:9 by Ryan J Ollos, 9 years ago

Release Notes: modified (diff)
Note: See TracTickets for help on using tickets.