Ticket #353 (new defect)

Opened 3 years ago

Last modified 2 weeks ago

A plug-in to allow Trac to render Markdown formatted text

Reported by: anonymous Assigned to: anybody
Priority: highest Component: Request-a-Hack
Severity: major Keywords:
Cc: Trac Release: 0.11

Description

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

Thanks!

Attachments

Markdown.py (1.2 kB) - added by killer_storm on 06/29/08 08:04:06.
Markdown plugin for Trac 0.11 (ebta)

Change History

09/05/06 05:45:35 changed 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.

09/13/06 16:13:28 changed by lianos

I'd really dig this, too

(follow-up: ↓ 4 ) 11/02/06 10:05:31 changed by gotoh

Very very easy solution is here.

## mkdown.py -- 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).

(in reply to: ↑ 3 ) 11/20/06 17:37:39 changed 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.

01/05/07 00:45:51 changed by brian@hawaii.edu

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
2007-01-04
"""

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(
                HREF,
                wiki_to_oneliner(target, hdf, env, env.get_db_cnx()),
                I).groups()[0]
        #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))

03/01/07 07:24:11 changed 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.

03/16/07 17:20:48 changed by Yura Ivanov

There is implementation of markdown in pure js: http://www.attacklab.net/showdown-gui.html And another js improvement of it (with syntax highlighting): http://softwaremaniacs.org/playground/showdown-highlight/

09/05/07 20:36:06 changed by anonymous

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

from trac.wiki.formatter import wiki_to_oneliner 

04/23/08 06:10:50 changed by fwolf.aide+trac@gmail.com

  • 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

http://michelf.com/projects/php-markdown/extra/

06/03/08 01:41:49 changed by athomas

  • owner changed from clp to anybody.
  • component changed from AccountLdapPlugin to Request-a-Hack.

06/29/08 08:04:06 changed by killer_storm

  • attachment Markdown.py added.

Markdown plugin for Trac 0.11 (ebta)

06/29/08 08:08:36 changed by killer_storm

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

  • copy file (Markdown.py 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
   
   markdown text goes here
   =======================
   ...
   }}}

(notice the capital letter M)

11/07/08 04:12:56 changed 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 http://www.freewisdom.org/projects/python-markdown/Releases and install it on your (most probably debian) system with

python setup.py install

after a server restart you should be able to use markdown

11/17/08 10:25:38 changed by STANT

97

11/17/08 10:29:54 changed by STANT

test

11/17/08 14:52:20 changed by STANT

mycomment

11/18/08 04:35:23 changed by STANT

test comment


Add/Change #353 (A plug-in to allow Trac to render Markdown formatted text)




Change Properties
Action