comparison core/mdexts/ssl_images.py @ 902:4dee923a2f6d

Merge with upstream.
author Brian Neal <bgneal@gmail.com>
date Sat, 07 Mar 2015 14:56:41 -0600
parents f12751259f66
children
comparison
equal deleted inserted replaced
901:147a66da9cbc 902:4dee923a2f6d
1 """
2 A python-markdown extension to turn <img> tags with http: source attributes into
3 <a> tags.
4 """
5 from urlparse import urlparse
6
7 import markdown
8
9
10 class SslImagesTreeprocessor(markdown.treeprocessors.Treeprocessor):
11
12 def run(self, root):
13 for node in root.iter('img'):
14 src = node.get('src')
15 if src:
16 url = urlparse(src)
17 if url.scheme == 'http':
18 node.clear()
19 node.tag = 'a'
20 node.text = 'Click for image'
21 node.set('href', url.geturl())
22
23
24 class SslImagesExtension(markdown.Extension):
25
26 def extendMarkdown(self, md, md_globals):
27 tree_proc = SslImagesTreeprocessor()
28 md.treeprocessors.add('ssl_images', tree_proc, '>inline')