def assertHtml(self, text, *args, **kwargs): value = Typograph.typograph_html(text, self.lang, **kwargs) value_hl = highlight(value) if not value_hl in args: print('\n') print(value_hl) for arg in args: print(arg) print('\n') self.assertIn(value_hl, args) value2 = Typograph.typograph_html(value, self.lang, **kwargs) if value != value2: print('\n'+highlight(value)+'\n'+highlight(value2)) self.assertEqual(highlight(value), highlight(value2))
def assertHtml(self, text, *args): value = Typograph.typograph_html(text, self.lang) value_hl = highlight(value) if not value_hl in args: print('\n') print(value_hl) for arg in args: print(arg) print('\n') self.assertIn(value_hl, args) value2 = Typograph.typograph_html(value, self.lang) if value != value2: print('\n' + highlight(value) + '\n' + highlight(value2)) self.assertEqual(highlight(value), highlight(value2))
def save(self, *args, **kwargs): # Make well-formed if requested if appsettings.FLUENT_TEXT_CLEAN_HTML: self.text = clean_html(self.text) # Remove unwanted tags if requested if appsettings.FLUENT_TEXT_SANITIZE_HTML: self.text = sanitize_html(self.text) # Set of common typography rules to the text plugin before save them if config.TYPOGRAPH_TEXT_PLUGIN_BEFORE_SAVE: self.text = Typograph.typograph_html(self.text, 'ru') super(TextItem, self).save(*args, **kwargs)
def assertText(self, text, *args, **kwargs): check_html = kwargs.pop('check_html', True) value = Typograph.typograph_text(text, self.lang, **kwargs) value_hl = highlight(value) if not value_hl in args: print('\n'+value_hl) for arg in args: print(arg) print('\n') self.assertIn(value_hl, args) if check_html: value2 = Typograph.typograph_html(value, self.lang) if value != value2: print('\n'+highlight(value)+'\n'+highlight(value2)) self.assertEqual(highlight(value), highlight(value2))
def assertText(self, text, *args, **kwargs): check_html = kwargs.pop('check_html', True) value = Typograph.typograph_text(text, self.lang, **kwargs) value_hl = highlight(value) if not value_hl in args: print('\n' + value_hl) for arg in args: print(arg) print('\n') self.assertIn(value_hl, args) if check_html: value2 = Typograph.typograph_html(value, self.lang) if value != value2: print('\n' + highlight(value) + '\n' + highlight(value2)) self.assertEqual(highlight(value), highlight(value2))
def full_clean(self, *args, **kwargs): """ RUS: Проверка данных текста формы. Текст должен быть проверен типографом и удалить непечатные символы. """ # This is called by the form when all values are assigned. # The pre filters are applied here, so any errors also appear as ValidationError. super(BlockItem, self).full_clean(*args, **kwargs) # todo: переделать через фильтры и сделать фильтр типографа последним, remove_unprintable сделать тоже фильтром self.text = Typograph.typograph_html(remove_unprintable(self.text), 'ru') self.text, self.text_final = apply_filters(self, self.text, field_name='text') if self.text_final == self.text: # No need to store duplicate content: self.text_final = None
def _typograph_support(self, context, caller=None): return Typograph.typograph_html(caller(), context['lang'])
def typograph(value): return mark_safe(Typograph.typograph_html(value, lang="ru"))