def clean(self, *args, **kwargs): """ RUS: Меняет шрифт текста в заголовке, подзаголовке, ЛИДе на шрифт Typograph. Ограничивает количество символов в заголовке до 90 знаков. """ self.title = Typograph.typograph_text(self.title, 'ru') if self.subtitle: self.subtitle = Typograph.typograph_text(self.subtitle, 'ru') if self.lead: self.lead = Typograph.typograph_text(self.lead, 'ru') max_length = getattr(settings, 'PUBLICATION_TITLE_MAX_LENGTH', 90) len_title = len(self.title) if len_title > max_length: raise ValidationError(_('The maximum number of characters {}, you have {}').format(max_length, len_title))
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 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 collect_replacements(env, item, body, tags=DEFAULT_TAGS, typography=False): if not isinstance(body, ExpandableMarkup): return body, [] try: doc = html.fragment_fromstring(body.markup, create_parent=True) except XMLSyntaxError: return body, [] replacements = [] for name, tag_cls in tags.items(): tags = tag_cls.from_doc(doc, name) for tag in tags: repl = tag.replace(env, item) if repl is not None: replacements.append(repl) if typography: Typograph.typograph_tree(doc, env.lang) return inner_html(doc), replacements
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 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 extra_clean(self, doc): if self.typograph: Typograph.typograph_tree(doc, self.lang) Cleaner.extra_clean(self, doc)
def do_typograph(context, value): return Typograph.typograph_text(value, context['lang'])
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"))