Opened 18 years ago

Closed 3 years ago

#353 closed defect (fixed)

Render Markdown formatted text

Reported by: anonymous Owned by: Cinc-th
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 16 years ago.
Markdown plugin for Trac 0.11 (ebta) (1.4 KB) - added by canton 15 years ago.
Bug fixes

Download all attachments as: .zip

Change History (28)

comment:1 Changed 18 years ago by petef

Priority: lowhighest
Severity: minormajor

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

comment:2 Changed 18 years ago by lianos

I'd really dig this, too

comment:3 Changed 18 years ago by Shun-ichi Goto

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 18 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 18 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 17 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 17 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 17 years ago by anonymous

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

from import wiki_to_oneliner 

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

Trac Release: 0.90.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 16 years ago by Alec Thomas

Component: AccountLdapPluginRequest-a-Hack
Owner: changed from Carlos López Pérez to anybody

Changed 16 years ago by killer_storm

Attachment: added

Markdown plugin for Trac 0.11 (ebta)

comment:11 Changed 16 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 16 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 15 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 15 years ago by canton

Attachment: added

Bug fixes

comment:18 Changed 15 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 15 years ago by anonymous

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

comment:20 Changed 15 years ago by Ryan J Ollos

Resolution: fixed
Status: newclosed
Summary: A plug-in to allow Trac to render Markdown formatted textRender Markdown formatted text

comment:21 Changed 13 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 12 years ago by Ryan J Ollos

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

comment:23 Changed 11 years ago by Ryan J Ollos

Component: Request-a-HackMarkdownMacro
Resolution: fixed
Status: closedreopened

Re-opening to consider implementing some of the changes in

comment:24 Changed 11 years ago by Ryan J Ollos

Owner: changed from anybody to Ryan J Ollos
Status: reopenednew

comment:25 Changed 11 years ago by Ryan J Ollos

Priority: highestnormal
Severity: majornormal

comment:26 Changed 10 years 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 10 years ago by Ryan J Ollos

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

comment:28 Changed 4 years ago by Ryan J Ollos

Owner: Ryan J Ollos deleted

comment:29 Changed 3 years ago by Cinc-th

Owner: set to Cinc-th
Status: newassigned

The macro now uses markdown extensions to render TracLinks, WikiMacros, WikiProcessors, code fences with highlighting and more.

Use current tunk (r18416 or later).

comment:30 Changed 3 years ago by Cinc-th

Resolution: fixed
Status: assignedclosed

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Cinc-th.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment

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

Note: See TracTickets for help on using tickets.