Mercurial > public > sg101
changeset 992:6816c5189525
No longer need Markdown extension SslImagesExtension.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 01 Nov 2015 15:59:12 -0600 |
parents | 4aadaf3bc234 |
children | 19b5a6ae3bca |
files | core/mdexts/ssl_images.py core/tests/test_mdexts.py |
diffstat | 2 files changed, 0 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/core/mdexts/ssl_images.py Sun Nov 01 15:56:05 2015 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -""" -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')
--- a/core/tests/test_mdexts.py Sun Nov 01 15:56:05 2015 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -"""Testing our custom Markdown extensions.""" - -import unittest - -import markdown - -from core.mdexts.ssl_images import SslImagesExtension - - -class SslImagesExtTestCase(unittest.TestCase): - """Tests for the SslImagesExtension.""" - - def setUp(self): - self.md = markdown.Markdown(extensions=[SslImagesExtension()]) - - def test_simple(self): - self.assertEqual(self.md.convert(''), '') - self.assertEqual(self.md.convert('1'), '<p>1</p>') - - def test_no_change(self): - self.assertEqual(self.md.convert('![image](https://example.com/1.jpg)'), - u'<p><img alt="image" src="https://example.com/1.jpg" /></p>') - - def test_change(self): - text = u'![image](http://example.com/1.jpg)' - html = u'<p><a href="http://example.com/1.jpg">Click for image</a></p>' - self.assertEqual(self.md.convert(text), html)