Edgewall Software

Opened 7 years ago

Last modified 6 months ago

#7728 new enhancement

Realm URL resolve function needed Trac Plugins

Reported by: martin@… Owned by:
Priority: normal Milestone: topic-wikiengine
Component: general Version:
Severity: minor Keywords: traclinks
Cc: martin@…
Release Notes:
API Changes:


In the current Trac code there seems to be no separate function/method to resolve a given TracLink to an full valid URL which can be used in XHTML code returned by macros.

I'm talking about macro similar to the Image macro which takes a trac realm like 'source:' or 'attachment:'. The Image macro has this resolving hardcoded while this should be an own method provided to all macros.

At the moment several macros on TracHacks (FlashViewPlugin, FreemindMacro, …) implement there own (sometimes incomplete and buggy) implementation of this.

An easy solution would be just to take the relevant code out of the Image macro and put it in an separate method. This must be already implemented somewhere else too because the same conversation is done by 'wiki_to_html' etc.

If there is already such an method I couldn't find it. I searched the trac source code, check several macro and the Nabble trac forum.

Attachments (1)

hrefexample.py (1.3 KB) - added by martin@… 7 years ago.
Example macro with clean href extraction code

Download all attachments as: .zip

Change History (10)

comment:1 Changed 7 years ago by martin@…

After going through a lot of trac and plugin code I found the (relative new?) method 'extract_link' which does half of the needed work. Because an 'Element' object is returned the href can be extracted without using an regular expression.

Because I couldn't find an example or documentation for this I coded a simple example so future macro developer have something to start with. Please find it attached. Please be aware that I'm a Perl programmer which is relative new to Python.

IMHO a method with code like this should be put in WikiMacroBase because many macro programmers need this.

Changed 7 years ago by martin@…

Example macro with clean href extraction code

comment:2 Changed 7 years ago by Remy Blank

  • Milestone set to 0.12
  • Owner set to Remy Blank

I'll look into this.

comment:3 Changed 6 years ago by Remy Blank

  • Milestone changed from 0.12 to 0.12.1

Not essential for 0.12.

comment:4 Changed 5 years ago by Christian Boos

  • Keywords traclinks added
  • Milestone changed from next-minor-0.12.x to 0.13
  • Owner changed from Remy Blank to Christian Boos
  • Severity changed from normal to minor

This will be possible with the WikiDom? API.

comment:5 Changed 5 years ago by Martin Scharrer <martin@…>

In the meantime I implemented the th:ExtractUrlPlugin to provide a way get the href of any TracLink. While this is good for me, I still think such a function should still be provided by Trac itself.

comment:6 Changed 5 years ago by Christian Boos

  • Milestone changed from 0.13 to 0.14-wikiengine

comment:7 Changed 21 months ago by Ryan J Ollos

  • Keywords traclink added; traclinks removed

comment:8 Changed 21 months ago by Ryan J Ollos

  • Keywords traclinks added; traclink removed

comment:9 Changed 6 months ago by Ryan J Ollos

  • Owner Christian Boos deleted

Modify Ticket

Change Properties
Set your email in Preferences
as new The ticket will remain with no owner.
The ticket will be disowned. Next status will be 'new'.
as The resolution will be set. Next status will be 'closed'.
The owner will be changed from (none) to anonymous. Next status will be 'assigned'.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.