Opened 6 weeks ago
Last modified 6 weeks ago
#14383 new enhancement
Markdown for tickets
Reported by: | technomancy | Owned by: | Cinc-th |
---|---|---|---|
Priority: | normal | Component: | MarkdownMacro |
Severity: | normal | Keywords: | |
Cc: | Trac Release: |
Description
In ticket:13926 it mentions using Markdown for ticket descriptions and comments. However, as far as I can tell from reading the source code for this plugin (admittedly I'm not a Python programmer) the only place that tickets are mentioned seems to be the code implementing the ability to reference tickets from Markdown wiki pages.
Is there a way to use this plugin to allow ticket descriptions and comments to be written in Markdown? If not, is it viable to add given the way Trac's plugin system works?
Attachments (0)
Change History (5)
comment:1 Changed 6 weeks ago by
comment:2 follow-up: 4 Changed 6 weeks ago by
Yes, I have tried the plugin, and I have found that markdown works fine for wiki pages, but not for ticket descriptions or ticket comments.
Right above the line you linked to in macro.py
, there is a comment which claims "We only handle wiki pages". But sure, maybe the comment is wrong?
In order to check, I added a print
call to the source; one on line 150, and one on line 152 inside the if
. The first print happens both when a wiki page is being converted to HTML and when a ticket description or comment is converted. However, the second print does not show for tickets, only wiki pages. This leads me to conclude that the comment is correct, and that the condition on line 151 prevents markdown formatting from being applied to ticket descriptions and comments.
(The "See also" link gives me a "Forbidden" error when I try to visit it.)
comment:3 Changed 6 weeks ago by
The process of debugging has made it pretty clear why Markdown isn't being applied to tickets. (It's because the conditional checks that data
has a path
key in it, which is never true for tickets, only for wiki pages.) I'm able to hack up my copy of the plugin to get it to do what I want pretty easily.
But my local fix is not appropriate to be submitted upstream because it applies Markdown unconditionally, and without knowing what kind of configuration options you want to use to determine whether to use Markdown or not, I can't really submit a patch that's suitable.
comment:4 Changed 6 weeks ago by
(The "See also" link gives me a "Forbidden" error when I try to visit it.)
I just adjusted configuration of trac.edgewall.org. Please try to visit it again.
comment:5 Changed 6 weeks ago by
Investigating it, I noticed that the feature which uses markdown as default wiki format works only for wiki pages. The same feature for tickets will work by the following patch:
-
tracmarkdown/macro.py
26 26 @version 0.11.4 27 27 """ 28 28 29 from functools import partial30 29 from pkg_resources import resource_filename 31 30 try: 32 31 from markdown import markdown, Markdown … … 102 101 "WikiFormatting.\n\nExample:\n" 103 102 "{{{#!ini\n[markdown]\nroot_pages = Docs, Note\n}}}\n**Note:** page names are " 104 103 "case sensitive.") 104 start_ticket_id = IntOption('markdown', 'start_ticket_id', '-1', 105 doc="Enables Markdown as the default format for ticket ids greater " 106 "than or equal to this value. Set to a negative number to " 107 "disable.") 105 108 106 109 # IRequestHandler methods 107 110 … … 144 147 return handler 145 148 146 149 def post_process_request(self, req, template, data, content_type): 150 if template and data: 151 if 'page' in data: 152 # We only handle wiki pages 153 path = data['page'].name.split('/') 154 if path[0] in self.root_pages: 155 data['wiki_to_html'] = self.wiki_to_html 156 if 'ticket' in data and self.start_ticket_id >= 0: 157 ticket = data['ticket'] 158 if not ticket.exists or ticket.id >= self.start_ticket_id: 159 data['wiki_to_html'] = self.wiki_to_html 160 add_stylesheet(req, 'markdown/css/markdown.css') 147 161 148 def wiki_to_html(self, context, wikidom, escape_newlines=None):149 return Markup(format_to_markdown(self, context, wikidom))150 151 if template and data and 'page' in data:152 # We only handle wiki pages153 path = data['page'].name.split('/')154 if path[0] in self.root_pages:155 data['wiki_to_html'] = partial(wiki_to_html, self)156 157 add_stylesheet(req, 'markdown/css/markdown.css')158 162 return template, data, content_type 159 163 160 164 # ITemplateProvider methods … … 165 169 def get_htdocs_dirs(self): 166 170 return [('markdown', resource_filename(__name__, 'htdocs'))] 167 171 172 # Internal methods 168 173 174 def wiki_to_html(self, context, wikidom, escape_newlines=None): 175 return Markup(format_to_markdown(self, context, wikidom)) 176 177 169 178 def format_to_markdown(self, context, content): 170 179 formatter = Formatter(self.env, context) 171 180 _sanitizer = TracHTMLSanitizer(
After r17933,
wiki_to_html
method is overridden at source:/markdownmacro/trunk/tracmarkdown/macro.py@18417:155#L146. Therefore, wiki text in ticket page should be rendered as markdown. Have you actually tried the plugin?See also: trac:source:/tags/trac-1.6/trac/ticket/templates/ticket_box.html@:212#L212