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
Example #2
0
    def extra_clean(self, doc):
        if self.typograph:
            Typograph.typograph_tree(doc, self.lang)

        Cleaner.extra_clean(self, doc)