Hi,

On 08.08.2017 14:19, Riedel, Torge wrote:


Hi,

I’m developing a trac macro to make it easier for wiki editors to add links to an external tool.

In Wiki-Markup they can then use a macro:

[[MyLink(my_value)]]

to have a link in trac style on their wiki page to the external tool.

The format of the link is similar to this:

myschema://myserver:1234/this/that/page?param1=value1&param2=value2&param3=my_value&param4=value4


Have you considered using Trac's InterWiki feature?
https://trac.edgewall.org/wiki/InterWiki

For example you could edit own InterMapTxt wiki page, adding something like:

mylinkmyschema://myserver:1234/this/that/page?param1=value1&param2=value2&param3=$1&param4=$2

and then write

mylink:value3:value4

to get a  link. If that's all you want then no plugin is needed.

My py code (I’m not a python developer, but developing C/C++. Google helps me with python) looks like this in the macro file (I modified the example from here https://trac.edgewall.org/wiki/0.12/WikiMacros):

from genshi.core import Markup

from trac.wiki.macros import WikiMacroBase

from trac.wiki import Formatter

import StringIO

class MyLinkMacro(WikiMacroBase):

        def expand_macro(self, formatter, name, text, args):

the_link = '[myschema://myserver:1234/this/that/page?param1=value1&param2=value2&param3=' + text + '&param4=value4 ' + text + ']'

                # Convert Wiki markup to HTML, new style

                out = StringIO.StringIO()

Formatter(self.env, formatter.context).format(the_link, out)

return Markup(out.getvalue())

My problem is, that the link is rendered but does not work afterwards because „&“ is replaced by „&“ and without any deeper knowledge of python and trac development I’m blocked in progress.

The code above actually seems to work (if "myschema " is replace by a known schema like "http").

A slightly simpler version:

from trac.wiki.macros import WikiMacroBase
from trac.wiki.formatter import format_to_html


class MyLinkMacro(WikiMacroBase):
        def expand_macro(self, formatter, name, text, args):
the_link = '[myschema://myserver:1234/this/that/page?param1=value1&param2=value2&param3=' + text + '&param4=value4 ' + text + ']'

return format_to_html(self.env, formatter.context, the_link)


--
You received this message because you are subscribed to the Google Groups "Trac 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to trac-users+unsubscr...@googlegroups.com.
To post to this group, send email to trac-users@googlegroups.com.
Visit this group at https://groups.google.com/group/trac-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to