File: comment_macro.py

package info (click to toggle)
trac-codecomments 1.1.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 348 kB
  • ctags: 191
  • sloc: python: 593; makefile: 2
file content (21 lines) | stat: -rw-r--r-- 714 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from code_comments.comments import Comments
from genshi.builder import tag
from trac.wiki.macros import WikiMacroBase

class CodeCommentLinkMacro(WikiMacroBase):
    """CodeCommentLink macro.
        This macro is used to embed a comment link in a ticket or wiki page:
        [[CodeCommentLink(5)]]
        where the number in the parentheses is the comment ID.
    """
    
    revision = "$Rev$"
    url = "$URL$"
    re = r'\[\[CodeCommentLink\((\d+)\)\]\]'
    
    def expand_macro(self, formatter, name, text, args):
        try:
            comment = Comments(formatter.req, formatter.env).by_id(text)
            return tag.a(comment.link_text(), href=comment.href())
        except:
            return ''