views:

57

answers:

1

I'm using python and using markdown. Is there a simple way to add a custom syntax? I want something like [ABC] expands to a certain tag or something.

or do I use regex?

+1  A: 

It appears that you can write extensions for Python-Markdown, which is probably the best approach.

If you are using some other Markdown implementation (or, you know, just for the heck of it) you could pre-process the text to implement your own tags (converting them to HTML) before handing it off to Markdown. This could be done using a regex or by any method you like. Within reasonable limits, Markdown should leave your HTML alone.

kindall
ya, im just worried about leaking unsafe html.
Timmy
@Timmy: Then "whitelist, not blacklist" ;) I.e. only expand a very limited set of tags that are known to be safe.
delnan
kindall
You can write extensions for Python-Markdown too, I just discovered. Added this to the top of my answer since it is probably the best approach.
kindall
Thx, didnt know that
Timmy