Opened 8 years ago

Last modified 7 months ago

#353 new defect

Render Markdown formatted text

Reported by: anonymous Owned by: rjollos
Priority: normal Component: MarkdownMacro
Severity: normal Keywords:
Cc: Trac Release: 0.11


I'd really like Trac to be able to handle Markdown formatted text. There is a python implementation of Markdown available here.


Attachments (2) (1.2 KB) - added by killer_storm 6 years ago.
Markdown plugin for Trac 0.11 (ebta) (1.4 KB) - added by canton 5 years ago.
Bug fixes

Download all attachments as: .zip

Change History (25)

comment:1 Changed 8 years ago by petef

  • Priority changed from low to highest
  • Severity changed from minor to major

I would love to see this. It would make such a difference to working with non-technical wiki authors.

comment:2 Changed 8 years ago by lianos

I'd really dig this, too

comment:3 follow-up: Changed 8 years ago by gotoh

Very very easy solution is here.

## -- easy markdown formatter without trac links.
rom markdown import markdown

# as for wiki-macro
def execute(hdf, txt, env):
    return markdown(txt.encode('utf-8'))

This macro does not handle trac links at all
but it might be possible using extension mechanism of current Markdown (1.6).

comment:4 in reply to: ↑ 3 Changed 8 years ago by turing

but it might be possible using extension mechanism of current Markdown (1.6).

A complete solution would be so fantastic, I'm weeping with anticipation.

comment:5 Changed 8 years ago by brian@…

I wrote this today. It's a little buggy, but seems usable. Things like
[Bob's patch]([40]) or [camel case]: CamelCase work. <CamelCase>
works but shows the whole url.

"""Trac plugin for Markdown Syntax (with links)

Everything markdown-ed as a link target is run through Trac's wiki
formatter to get a substitute url.

Tested with Trac 0.8.1 and python-markdown 1.4 on Debian GNU/Linux.

Brian Jaress

from re import sub, compile, search, I
from markdown import markdown
from trac.WikiFormatter import wiki_to_oneliner

#links, autolinks, and reference-style links
LINK = compile(
    r'(\]\()([^) ]+)([^)]*\))|(<)([^>]+)(>)|(\n\[[^]]+\]: *)([^ \n]+)(.*\n)'

HREF = compile(r'href=[\'"]?([^\'" ]*)')

def execute(hdf, txt, env):
    abs = env.abs_href.base
    abs = abs[:len(abs) - len(env.href.base)]
    def convert(m):
        pre, target, suf = filter(None, m.groups())
        url = search(
                wiki_to_oneliner(target, hdf, env, env.get_db_cnx()),
        #Trac creates relative links, which markdown won't touch inside
        # <autolinks> because they look like HTML
        if pre == '<' and url != target:
            pre += abs
        return pre + str(url) + suf

    return markdown(sub(LINK, convert, txt))

comment:6 Changed 8 years ago by anonymous

+ for markdown support

However the only way Markdown is really going to be adopted this way is if we can use it as the default text markup. As soon as we need # etc and to close then Markdown will not get used.

So we need it to be in trac.ini to support default without //!/# / tricks.

comment:7 Changed 8 years ago by Yura Ivanov

There is implementation of markdown in pure js:
And another js improvement of it (with syntax highlighting):

comment:8 Changed 7 years ago by anonymous

For the trac version I have this needs a tiny edit:

from import wiki_to_oneliner 

comment:9 Changed 6 years ago by fwolf.aide+trac@…

  • Trac Release changed from 0.9 to 0.11

I'd like to see we can write in trac using Markdown syntax too...

And also, here an Markdown Extra which extended original Markdown

comment:10 Changed 6 years ago by athomas

  • Component changed from AccountLdapPlugin to Request-a-Hack
  • Owner changed from clp to anybody

Changed 6 years ago by killer_storm

Markdown plugin for Trac 0.11 (ebta)

comment:11 Changed 6 years ago by killer_storm

i've adapted version by brian for Trac version 0.11.

  • copy file ( from attachments) into yourproject/plugins.
  • install markdown (e.g. apt-get install python-markdown on Debian/Ubuntu).
  • restart webserver and enjoy

you can use it as wiki processor:

   markdown text goes here

(notice the capital letter M)

comment:12 Changed 6 years ago by knittl

if you get this error:

Trac detected an internal error:

AttributeError: 'unicode' object has no attribute 'parent'

you have to get the latest python-markdown version with unicode support from and install it on your (most probably debian) system with

python install

after a server restart you should be able to use markdown

comment:17 Changed 5 years ago by antony

To add support for Markdown Extra, change the line

return markdown(sub(LINK, convert, txt))

to read

return markdown(sub(LINK, convert, txt), ['extra'])

To allow escaping of links using an exclamation mark, eg:


change the line

LINK = compile(
    r'(\]\()([^) ]+)([^)]*\))|(<)([^>]+)(>)|(\n\[[^]]+\]: *)([^ \n]+)(.*\n)'

to read

LINK = compile(
    r'(\]\()([^) !]+)([^)]*\))|(<)([^>]+)(>)|(\n\[[^]]+\]: *)([^ \n]+)(.*\n)'

in the attacked

Changed 5 years ago by canton

Bug fixes

comment:18 Changed 5 years ago by anonymous

Added with the following bug fixes to killer_storm's code:

  • Allowed escaping of Trac links, so eg [Link](!#1) will become [Link](#1) instead of [Link](!/ticket/1)
  • Fixed a bug where a markdown link containing a target location that Trac doesn't think is a valid link would cause an Internal Error
  • <CamelCase> no longer shows the whole URL

comment:19 Changed 5 years ago by anonymous

There seems to be a trac-hacks page for this now: MarkdownMacro.

comment:20 Changed 5 years ago by rjollos

  • Resolution set to fixed
  • Status changed from new to closed
  • Summary changed from A plug-in to allow Trac to render Markdown formatted text to Render Markdown formatted text

comment:21 Changed 3 years ago by anonymous

In Python 2.6, Trac 0.12

need to change

            href_match = search(


            href_match = search(


    HREF = compile(r'href=[\'"]?([^\'" ]*)')


    HREF = compile(r'href=[\'"]?([^\'" ]*)', I)

comment:22 Changed 2 years ago by rjollos

MarkdownMacro has been patched. Please try out the latest source, version 0.11.2.

comment:23 Changed 16 months ago by rjollos

  • Component changed from Request-a-Hack to MarkdownMacro
  • Resolution fixed deleted
  • Status changed from closed to reopened

Re-opening to consider implementing some of the changes in

comment:24 Changed 16 months ago by rjollos

  • Owner changed from anybody to rjollos
  • Status changed from reopened to new

comment:25 Changed 16 months ago by rjollos

  • Priority changed from highest to normal
  • Severity changed from major to normal

comment:26 Changed 7 months ago by Sander.Maijers @…

Today I fetched the latest SVN version of MarkdownMacro, installed it on Trac 1.0.1.
My test shows that fenced code blocks are not being parsed, while the Markdown library supports this syntax:

comment:27 Changed 7 months ago by rjollos

I'm not sure when I will have time to work on this, but I'd gladly accept a patch.

Add Comment

Modify Ticket

as new .

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.