Here’s a quick snippet that shows how to disable images (or any extension) in Python Markdown:
import markdown class MyMarkdownExtension(markdown.Extension): def extendMarkdown(self, md, md_globals): del md.inlinePatterns['image_link'] del md.inlinePatterns['image_reference'] my_markdown_extension = MyMarkdownExtension() raw_text = 'This is a test image: ' print markdown.markdown(raw_text, [my_markdown_extension], safe_mode = 'escape')
Edit:
Some processing is disabled through md.parser.blockprocessors instead.
Here are the options for each:
md.inlinePatterns:
'backtick' 'escape' 'reference' 'link' 'image_link' 'image_reference' 'short_reference' 'autolink' 'automail' 'linebreak2' 'linebreak' 'html' 'entity' 'not_strong' 'strong_em' 'strong' 'emphasis' 'emphasis2'
md.parser.blockprocessors:
'indent' 'code' 'hashheader' 'setextheader' 'hr' 'olist' 'ulist' 'quote' 'paragraph'
#1 by guest on June 7, 2011 - 1:01 pm
Thanks, very useful.
#2 by guest on June 7, 2011 - 1:59 pm
Just a little remark:
On python-markdown 2.0.3 you should create Markdown object to pass your own extension.
md = markdown.Markdown(extensions=[my_markdown_extension], safe_mode='escape')
print md.convert(raw_text)
#3 by Sean Fujiwara on June 7, 2011 - 10:34 pm
Ahh, thanks. I should have mentioned that I was using python markdown 2.1.0.
#4 by Patricia Juarez (@ccsakuweb) on August 18, 2011 - 1:08 am
Thank you very muxh, it was useful. But I would like to disable more tags of markdown.
I want a version extended and another one minified.
The extended would be the normal markdown, but in the minified I don’t want to let code, hr, lists, quote, paragraphs.. you know how to disable them? It would be really useful. Please help.
#5 by Sean Fujiwara on August 18, 2011 - 1:57 am
These elements appear to be in the
md.parser.blockprocessorsobject. I’ll edit the post to include all the things you can disable.