{"id":133,"date":"2011-09-13T13:05:06","date_gmt":"2011-09-13T17:05:06","guid":{"rendered":"http:\/\/www.jetmore.org\/john\/blog\/?p=133"},"modified":"2012-05-11T15:14:48","modified_gmt":"2012-05-11T19:14:48","slug":"using-wiki-markup-in-trac-custom-ticket-fields","status":"publish","type":"post","link":"https:\/\/www.jetmore.org\/john\/blog\/2011\/09\/using-wiki-markup-in-trac-custom-ticket-fields\/","title":{"rendered":"Using Wiki Markup in Trac Custom Ticket Fields"},"content":{"rendered":"<p>Yesterday I worked on streamlining our ticket workflow in Trac.  While I was in the test project anyway, I decided to address an issue that had bugged me since I first set up Trac.  I originally set up two custom ticket fields related to case IDs in our CRM system:<\/p>\n<pre class=\"brush: plain; light: true; title: ; notranslate\" title=\"\">\r\ncrmnum = text\r\ncrmnum.label = Case #\r\ncrmnum.format = plain\r\ncrmnum.order = 1\r\ncrmlink = text\r\ncrmlink.label = Case Link\r\ncrmlink.format = wiki\r\ncrmlink.order = 3\r\n<\/pre>\n<p>The idea was that we could have the &#8220;<code>crmnum<\/code>&#8221; field to just hold the ID, which we could act on programmatically.  The &#8220;<code>crmlink<\/code>&#8221; field would be a copy\/paste link of the ticket&#8217;s URL, which would allow someone looking at the ticket to click through to the CRM case easily.<\/p>\n<p>The problem with this is that the link is long and ugly and completely throws off the tidiness of the ticket summary.<\/p>\n<p>So, <a href=\"https:\/\/www.jetmore.org\/john\/blog\/2011\/09\/custom-testlink-macro-for-trac\/\">having recently figured out how to write a custom wiki macro<\/a>, I decided to create one for links to our CRM system also.  The idea would be that the &#8220;<code>crmlink<\/code>&#8221; field would go away and the &#8220;<code>crmnum<\/code>&#8221; field could be updated to use the wiki Macro to generate the link automatically.<\/p>\n<p>I nuked the &#8220;<code>crmlink<\/code>&#8221; field and changed &#8220;<code>crmnum<\/code>&#8221; from &#8220;<code>type = plain<\/code>&#8221; to &#8220;<code>type = wiki<\/code>&#8220;.  I wrote my custom CRM macro, testing it in the wiki itself until I had it behaving.  I then created a new ticket, entered <code>[[CRM(123)]]<\/code> in the crmnum field, and clicked &#8220;Preview&#8221;.  Instead of seeing the link it should have returned, instead I got <code>[[CRM(...)]]<\/code>.  I did some testing and proved to myself that some wiki processing was taking place (ticket:1 expanded correctly) and that no macro expanded in that field, including built-in macros.<\/p>\n<p>Then on a hunch, I changed crmnum to &#8220;<code>type = textarea<\/code>&#8221; instead of &#8220;<code>type = text<\/code>&#8220;.  Sure enough, macros work properly in textarea fields but not text fields.  In a way this makes sense since almost all built-in macros return multiple lines of text.  The <a href=\"http:\/\/trac.edgewall.org\/wiki\/TracTicketsCustomFields\">documentation for custom ticket fields<\/a> doesn&#8217;t mention that wiki processing behavior differs between these field types.  Unfortunately the textarea fields can&#8217;t easily be tricked into looking like a simple text field.  They come with an editing bar, and they are assigned the same class as the description field, so you can&#8217;t easily use CSS tricks on it.<\/p>\n<p>I was unsure if this was a bug or intentional, but I managed to find the <a href=\"http:\/\/trac.edgewall.org\/ticket\/1791\">original Trac ticket for adding wiki processing to custom fields<\/a>, and it&#8217;s clear that it was intentional to make the wiki-processing behavior of the two field types differ.  Specifically, text fields are processed with <code>format_to_oneliner()<\/code> and textareas are processed with <code>format_to_html()<\/code> (this can be seen in <a href=\"http:\/\/trac.edgewall.org\/changeset\/7563\">the change to web_ui.py associated with new feature<\/a>.<\/p>\n<p>After figuring out that the text\/textarea parsing differences were done intentionally, I lost interest in patching the code itself.  Instead I looked into <a href=\"https:\/\/www.jetmore.org\/john\/blog\/2011\/09\/linking-to-testlink-testcases-from-trac-addendum\/\">using InterWiki links instead of macros<\/a>, which are processed in text fields.<\/p>\n<p>I created <a href=\"http:\/\/trac.edgewall.org\/ticket\/10352\">trac ticket 10352<\/a> about this issue, hopefully it gets addressed one way or another.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday I worked on streamlining our ticket workflow in Trac. While I was in the test project anyway, I decided to address an issue that had bugged me since I first set up Trac. I originally set up two custom &hellip; <a href=\"https:\/\/www.jetmore.org\/john\/blog\/2011\/09\/using-wiki-markup-in-trac-custom-ticket-fields\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[8,14],"_links":{"self":[{"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/posts\/133"}],"collection":[{"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/comments?post=133"}],"version-history":[{"count":3,"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/posts\/133\/revisions"}],"predecessor-version":[{"id":686,"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/posts\/133\/revisions\/686"}],"wp:attachment":[{"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/media?parent=133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/categories?post=133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/tags?post=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}