Mercurial > public > sg101
view core/mdexts/ssl_images.py @ 973:6f55c086db1e
Guess file extension based on content-type.
When downloading a file, and no path is supplied to store it, guess the file
extension using mimetypes and the content-type header.
Also supply a unit test for the HotLinkImageForm.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 01 Oct 2015 19:44:45 -0500 |
parents | f12751259f66 |
children |
line wrap: on
line source
""" A python-markdown extension to turn <img> tags with http: source attributes into <a> tags. """ from urlparse import urlparse import markdown class SslImagesTreeprocessor(markdown.treeprocessors.Treeprocessor): def run(self, root): for node in root.iter('img'): src = node.get('src') if src: url = urlparse(src) if url.scheme == 'http': node.clear() node.tag = 'a' node.text = 'Click for image' node.set('href', url.geturl()) class SslImagesExtension(markdown.Extension): def extendMarkdown(self, md, md_globals): tree_proc = SslImagesTreeprocessor() md.treeprocessors.add('ssl_images', tree_proc, '>inline')