Ejemplo n.º 1
0
    def add_child_element(self, tag_address, value, tag_set_name=None):

        from dentmark.dentmark import defs_manager

        tag_set = defs_manager.get_tag_set(tag_set_name)
        tag_def = tag_set.get_def(tag_address)

        if tag_def is None:
            raise Exception(f"Not a defined tag address: {tag_address}")

        # TODO just use None for values that can't be calculated. A bit hackish, but will
        # be fine to just re-generate the dentmark code. Not going to render this tree
        tag_address = f'{self.parent.address}.{tag_def.tag_name}'
        tag_def_inst = tag_def(tag_def.tag_name,
                               tag_address, None, None, self, self.root,
                               len(self.children), None, False, False,
                               self.extra_context)

        from dentmark.text_node import TextNode

        text_node_inst = TextNode(None, None, tag_def_inst, self.root, 0,
                                  value, False, self.extra_context)
        tag_def_inst.children.append(text_node_inst)
        self.children.append(tag_def_inst)

        tag_def_inst_relations = tag_set.get_children_relations(
            tag_def_inst.address)
        tag_def_inst.check_children(tag_def_inst_relations)

        children_relations = tag_set.get_children_relations(self.address)
        self.check_children(children_relations)
Ejemplo n.º 2
0
from dentmark.tag_def import TagDef, Optional, OptionalUnique, Required, RequiredUnique

from dentmark.dentmark import defs_manager
def_tag_set = defs_manager.get_tag_set()


@def_tag_set.register()
class Annotation(TagDef):
    tag_name = 'a8n'

    parents = [
        Optional('root.p'),
        Optional('root.bq'),
        Optional('root.bq.p'),
        Optional('root.ul.li')
    ]  #TODO maybe this can be root level as well? Maybe blockquote too?

    def render_main(self):
        nth_of_type = self.nth_of_type + 1
        sup_id = f'fnref:{nth_of_type}'
        href = f'#fn:{nth_of_type}'

        return f'<span class="annotation__underline">{self.content}</span><sup id="{sup_id}"><a href="{href}" class="footnote-ref" role="doc-noteref">[{nth_of_type}]</a></sup>'


@def_tag_set.register()
class FootNote(TagDef):
    tag_name = 'fn'
    add_to_collector = True

    parents = [