Edgewall Software
Modify

Opened 21 years ago

Closed 20 years ago

Last modified 18 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:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description (last modified by Christopher Lenz)

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 by naked@…, 21 years ago

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 @@
             line=lineno)
     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,
                 content_offset,block_text,state,state_machine):
@@ -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 by anonymous, 21 years ago

Milestone: 0.7
Owner: changed from Jonas Borgström to anonymous
Status: newassigned

comment:3 by daniel, 21 years ago

Owner: changed from anonymous to daniel

comment:4 by daniel, 21 years ago

Resolution: fixed
Status: assignedclosed

Awesome contribution. Thank you very much.

Merged and fixed in [462].

comment:5 by anonymous, 20 years ago

Resolution: fixed
Status: closedreopened

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

comment:6 by Christopher Lenz, 20 years ago

Description: modified (diff)
Milestone: 0.70.9

comment:7 by anonymous, 20 years ago

I think patch in #801 fixes this.

comment:8 by Mark Rowe, 20 years ago

Resolution: worksforme
Status: reopenedclosed

Works for me in current trunk.

comment:9 by Matthew Good, 19 years ago

Milestone: 0.9

Modify Ticket

Change Properties
Set your email in Preferences
Action
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.