Edgewall Software

Opened 11 years ago

Closed 10 years ago

Last modified 8 years ago

#273 closed enhancement (worksforme)

reStructuredText should define a TracLinks role

Reported by: naked@… Owned by: daniel
Priority: normal Milestone:
Component: wiki system Version: devel
Severity: normal Keywords:
Release Notes:
API Changes:

Description (last modified by cmlenz)

As WikiRestructuredTextLinks are a reality now, there should also be an interpreted text role for TracLinks. That is, to be able to say:

There is `WikiPage`:trac: and issue `#12`:trac: here.

Instead of the really awkward current way:

There is |WikiPage| and issue |#12| here.

.. |WikiPage| trac:: WikiPage
.. |#12| trac:: #12

A possible option could be even having the trac interpreted text role as a default, so one could even leave out the ":trac:" part from those, but that would be incompatible with pages that expect it to be the default title-reference role.

Attachments (0)

Change History (9)

comment:1 Changed 11 years ago by naked@…

I created a trivial implementation of this, as proof of concept. I don't know python, and there's no error processing, but it should be trivial to fix this into a proper form by someone who actually knows what he's doing.

Index: trac/wikimacros/rst.py
--- trac/wikimacros/rst.py      (revision 442)
+++ trac/wikimacros/rst.py      (working copy)
@@ -31,6 +31,8 @@
 from docutils import nodes
 from docutils.core import publish_string
 from docutils.parsers.rst import directives
+from docutils.parsers.rst import states
+from docutils.parsers import rst
 from trac.Href import Href
@@ -128,6 +130,15 @@
     return [warning]
+def trac_role(href, name,rawtext,text,lineno):
+    for (pattern, function) in LINKS:
+        m = pattern.match(text)
+        if m:
+            uri,text = function(href, m,[text])
+            return [nodes.reference(rawtext, text, refuri=uri)], []
+    return [], []
 def execute(hdf, text, env): 
     def do_trac(name,arguments,options,content,lineno,
@@ -139,5 +150,12 @@
     do_trac.content = None
     directives.register_directive('trac', do_trac)
-    html = publish_string(text, writer_name = 'html')
+    def do_trac_role(name,rawtext,text,lineno):
+        return trac_role(env.href, name,rawtext,text,lineno)
+    local_roles = {'trac': do_trac_role}
+    _inliner = states.Inliner(roles = local_roles)
+    _parser = rst.Parser(inliner = _inliner)
+    html = publish_string(text, writer_name = 'html', parser = _parser)
     return html[html.find('<body>')+6:html.find('</body>')].strip()

comment:2 Changed 11 years ago by anonymous

  • Milestone set to 0.7
  • Owner changed from jonas to anonymous
  • Status changed from new to assigned

comment:3 Changed 11 years ago by daniel

  • Owner changed from anonymous to daniel

comment:4 Changed 11 years ago by daniel

  • Resolution set to fixed
  • Status changed from assigned to closed

Awesome contribution. Thank you very much.

Merged and fixed in [462].

comment:5 Changed 10 years ago by anonymous

  • Resolution fixed deleted
  • Status changed from closed to reopened

`#12`:trac: works, but `ticket:12`:trac: does not.

comment:6 Changed 10 years ago by cmlenz

  • Description modified (diff)
  • Milestone changed from 0.7 to 0.9

comment:7 Changed 10 years ago by anonymous

I think patch in #801 fixes this.

comment:8 Changed 10 years ago by mrowe

  • Resolution set to worksforme
  • Status changed from reopened to closed

Works for me in current trunk.

comment:9 Changed 10 years ago by mgood

  • Milestone 0.9 deleted

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain daniel.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from daniel to the specified user.

Add Comment

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

Note: See TracTickets for help on using tickets.