Opened 19 years ago
Closed 4 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 |
Attachments (2)
Change History (28)
comment:1 Changed 18 years ago by
Priority: | low → highest |
---|---|
Severity: | minor → major |
comment:3 follow-up: 4 Changed 18 years ago by
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).
comment:4 Changed 18 years ago by
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
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))
comment:6 Changed 18 years ago by
+ 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 18 years ago by
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/
comment:8 Changed 17 years ago by
For the trac version I have this needs a tiny edit:
from trac.wiki.formatter import wiki_to_oneliner
comment:9 Changed 17 years ago by
Trac Release: | 0.9 → 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 17 years ago by
Component: | AccountLdapPlugin → Request-a-Hack |
---|---|
Owner: | changed from Carlos López Pérez to anybody |
comment:11 Changed 16 years ago by
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)
comment:12 Changed 16 years ago by
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
comment:17 Changed 15 years ago by
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:
[Ticket](!#1)
change the line
LINK = compile( r'(\]\()([^) ]+)([^)]*\))|(<)([^>]+)(>)|(\n\[[^]]+\]: *)([^ \n]+)(.*\n)' )
to read
LINK = compile( r'(\]\()([^) !]+)([^)]*\))|(<)([^>]+)(>)|(\n\[[^]]+\]: *)([^ \n]+)(.*\n)' )
in the attacked Markdown.py
comment:18 Changed 15 years ago by
Added Markdown.2.py 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:20 Changed 15 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Summary: | A plug-in to allow Trac to render Markdown formatted text → Render Markdown formatted text |
comment:21 Changed 14 years ago by
In Python 2.6, Trac 0.12
need to change
href_match = search( HREF, out.getvalue(), I)
to
href_match = search( HREF, out.getvalue())
and
HREF = compile(r'href=[\'"]?([^\'" ]*)')
to
HREF = compile(r'href=[\'"]?([^\'" ]*)', I)
comment:22 Changed 12 years ago by
MarkdownMacro has been patched. Please try out the latest source, version 0.11.2.
comment:23 Changed 12 years ago by
Component: | Request-a-Hack → MarkdownMacro |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
Re-opening to consider implementing some of the changes in Markdown.2.py.
comment:24 Changed 12 years ago by
Owner: | changed from anybody to Ryan J Ollos |
---|---|
Status: | reopened → new |
comment:25 Changed 12 years ago by
Priority: | highest → normal |
---|---|
Severity: | major → normal |
comment:26 Changed 11 years ago by
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: http://pythonhosted.org/Markdown/extensions/fenced_code_blocks.html
comment:27 Changed 11 years ago by
I'm not sure when I will have time to work on this, but I'd gladly accept a patch.
comment:28 Changed 5 years ago by
Owner: | Ryan J Ollos deleted |
---|
comment:29 Changed 4 years ago by
Owner: | set to Cinc-th |
---|---|
Status: | new → assigned |
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 4 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
I would love to see this. It would make such a difference to working with non-technical wiki authors.