Edgewall Software
Modify

Opened 6 years ago

Last modified 5 months ago

#7728 new enhancement

Realm URL resolve function needed Trac Plugins

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

Description

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@… 6 years ago.
Example macro with clean href extraction code

Download all attachments as: .zip

Change History (9)

comment:1 Changed 6 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 6 years ago by martin@…

Example macro with clean href extraction code

comment:2 Changed 6 years ago by rblank

  • Milestone set to 0.12
  • Owner set to rblank

I'll look into this.

comment:3 Changed 5 years ago by rblank

  • Milestone changed from 0.12 to 0.12.1

Not essential for 0.12.

comment:4 Changed 4 years ago by cboos

  • Keywords traclinks added
  • Milestone changed from next-minor-0.12.x to 0.13
  • Owner changed from rblank to cboos
  • Severity changed from normal to minor

This will be possible with the WikiDom? API.

comment:5 Changed 4 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 4 years ago by cboos

  • Milestone changed from 0.13 to 0.14-wikiengine

comment:7 Changed 5 months ago by rjollos

  • Keywords traclink added; traclinks removed

comment:8 Changed 5 months ago by rjollos

  • Keywords traclinks added; traclink removed

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new The owner will remain cboos.
as The resolution will be set. Next status will be 'closed'.
The owner will be changed from cboos to anonymous. Next status will be 'assigned'.
Author


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

 
Note: See TracTickets for help on using tickets.