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:
|
|
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.
Change History
(9)
| Milestone: |
→ 0.7
|
| Owner: |
changed from Jonas Borgström to anonymous
|
| Status: |
new → assigned
|
| Owner: |
changed from anonymous to daniel
|
| Resolution: |
→ fixed
|
| Status: |
assigned → closed
|
| Resolution: |
fixed
|
| Status: |
closed → reopened
|
| Description: |
modified (diff)
|
| Milestone: |
0.7 → 0.9
|
| Resolution: |
→ worksforme
|
| Status: |
reopened → closed
|
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()