Ticket #7728 (new enhancement)
Opened 4 years ago
Last modified 16 months ago
Realm URL resolve function needed Trac Plugins
| Reported by: | martin@… | Owned by: | cboos |
|---|---|---|---|
| Priority: | normal | Milestone: | 0.14-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
Change History
comment:1 Changed 4 years ago by martin@…
Changed 4 years ago by martin@…
- Attachment hrefexample.py added
Example macro with clean href extraction code
comment:2 Changed 4 years ago by rblank
- Milestone set to 0.12
- Owner set to rblank
I'll look into this.
comment:3 Changed 3 years ago by rblank
- Milestone changed from 0.12 to 0.12.1
Not essential for 0.12.
comment:4 Changed 2 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 21 months 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 16 months ago by cboos
- Milestone changed from 0.13 to 0.14-wikiengine



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.