annotate core/mdexts/ssl_images.py @ 943:cf9918328c64

Haystack tweaks for Django 1.7.7. I had to upgrade to Haystack 2.3.1 to get it to work with Django 1.7.7. I also had to update the Xapian backend. But I ran into problems. On my laptop anyway (Ubuntu 14.0.4), xapian gets mad when search terms are greater than 245 chars (or something) when indexing. So I created a custom field that would simply omit terms greater than 64 chars and used this field everywhere I previously used a CharField. Secondly, the custom search form was broken now. Something changed in the Xapian backend and exact searches stopped working. Fortunately the auto_query (which I was using originally and broke during an upgrade) started working again. So I cut the search form back over to doing an auto_query. I kept the form the same (3 fields) because I didn't want to change the form and I think it's better that way.
author Brian Neal <bgneal@gmail.com>
date Wed, 13 May 2015 20:25:07 -0500
parents f12751259f66
children
rev   line source
bgneal@883 1 """
bgneal@883 2 A python-markdown extension to turn <img> tags with http: source attributes into
bgneal@883 3 <a> tags.
bgneal@883 4 """
bgneal@883 5 from urlparse import urlparse
bgneal@883 6
bgneal@883 7 import markdown
bgneal@883 8
bgneal@883 9
bgneal@883 10 class SslImagesTreeprocessor(markdown.treeprocessors.Treeprocessor):
bgneal@883 11
bgneal@883 12 def run(self, root):
bgneal@883 13 for node in root.iter('img'):
bgneal@883 14 src = node.get('src')
bgneal@883 15 if src:
bgneal@883 16 url = urlparse(src)
bgneal@883 17 if url.scheme == 'http':
bgneal@883 18 node.clear()
bgneal@883 19 node.tag = 'a'
bgneal@883 20 node.text = 'Click for image'
bgneal@883 21 node.set('href', url.geturl())
bgneal@883 22
bgneal@883 23
bgneal@883 24 class SslImagesExtension(markdown.Extension):
bgneal@883 25
bgneal@883 26 def extendMarkdown(self, md, md_globals):
bgneal@883 27 tree_proc = SslImagesTreeprocessor()
bgneal@883 28 md.treeprocessors.add('ssl_images', tree_proc, '>inline')