def testApersands(self): self.assertEquals(typogrify.amp('One & two'), 'One <span class="amp">&</span> two') self.assertEquals(typogrify.amp('One & two'), u'One <span class="amp">&</span> two') self.assertEquals(typogrify.amp('One & two'), u'One <span class="amp">&</span> two') self.assertEquals(typogrify.amp('One & two'), u'One <span class="amp">&</span> two') self.assertEquals(typogrify.amp('One <span class="amp">&</span> two'), u'One <span class="amp">&</span> two') self.assertEquals(typogrify.amp('“this” & <a href="/?that&test">that</a>'), u'“this” <span class="amp">&</span> <a href="/?that&test">that</a>') self.assertEquals(typogrify.amp('<link href="xyz.html" title="One & Two">xyz</link>'), u'<link href="xyz.html" title="One & Two">xyz</link>')
def pre_save(self, model_instance, add): value = getattr(model_instance, self.attname) markup = getattr(model_instance, self._markup_choices) if markup == 'markdown': md = Markdown() html = md.convert(value) elif markup == 'plain': html = linebreaks(amp(value), autoescape=True) elif markup == 'textile': html = textile(value) elif markup == 'rest': from asgard.utils import rest_directives docutils_settings = getattr(settings, "RESTRUCTUREDTEXT_FILTER_SETTINGS", {}) parts = publish_parts(source=value, writer_name="html4css1", settings_overrides=docutils_settings) html = parts["fragment"] else: html = value setattr(model_instance, self._html_field, html) return value