Exemplo n.º 1
0
    def process_node(self, node):
        node['label_id'] = '-'.join(node['label'])
        self.process_node_title(node)

        node['html_label'] = to_markup_id(node['label'])
        node['markup_id'] = "-".join(node['html_label'])
        node['tree_level'] = len(node['label']) - 1

        list_level, list_type = self.list_level(
            node['label'], node['node_type'])

        node['list_level'] = list_level

        # exception for situations in which we have unnumbered definitions
        # unnumbered defs have the last part of their label in CamelCase
        # and the word "means" in their text
        if re.search('([A-Z][a-z]+)+', node['label'][-1]) and re.search('means', node['text']):
            node['list_type'] = 'no-marker'
        else:
            node['list_type'] = list_type

        if len(node['text']):
            inline_elements = self.inline_applier.get_layer_pairs(
                node['label_id'], node['text'])
            search_elements = self.search_applier.get_layer_pairs(
                node['label_id'])

            if self.diff_applier:
                node['marked_up'] = self.diff_applier.apply_diff(
                    node['text'], node['label_id'])

            layers_applier = LayersApplier()
            layers_applier.enqueue_from_list(inline_elements)
            layers_applier.enqueue_from_list(search_elements)

            if 'marked_up' in node:
                node['marked_up'] = layers_applier.apply_layers(
                    node['marked_up'])
            else:
                node['marked_up'] = layers_applier.apply_layers(node['text'])
            node['marked_up'] = HTMLBuilder.section_space(node['marked_up'])

        node = self.p_applier.apply_layers(node)

        if 'TOC' in node:
            for l in node['TOC']:
                l['label'] = HTMLBuilder.section_space(l['label'])

        if 'interp' in node and 'markup' in node['interp']:
            node['interp']['markup'] = HTMLBuilder.section_space(
                node['interp']['markup'])

        if node['node_type'] == INTERP:
            self.modify_interp_node(node)

        for c in node['children']:
            self.process_node(c)
Exemplo n.º 2
0
    def process_node(self, node):
        """Every node passes through this function on the way to being
        rendered. Importantly, this adds the `marked_up` field, which contains
        the HTML version of node's text (after applying all relevant
        layers) and the `template_name` field, which defines how this node
        should be rendered."""

        node['label_id'] = '-'.join(node['label'])
        self.process_node_title(node)
        node['is_collapsed'] = self.is_collapsed(node)

        node['html_label'] = to_markup_id(node['label'])
        node['markup_id'] = "-".join(node['html_label'])
        node['tree_level'] = len(node['label']) - 1

        list_level = self.list_level(node['label'], node['node_type'])

        node['list_level'] = list_level

        if len(node['text']):
            inline_elements = self.inline_applier.get_layer_pairs(
                node['label_id'], node['text'])
            search_elements = self.search_applier.get_layer_pairs(
                node['label_id'])

            if self.diff_applier:
                node['marked_up'] = self.diff_applier.apply_diff(
                    node['text'], node['label_id'])

            layers_applier = LayersApplier()
            layers_applier.enqueue_from_list(inline_elements)
            layers_applier.enqueue_from_list(search_elements)

            node['marked_up'] = layers_applier.apply_layers(
                node.get('marked_up', node['text']))
            node['marked_up'] = self.section_space(node['marked_up'])
            node['marked_up'] = flatten_links(node['marked_up'])

        node = self.p_applier.apply_layers(node)

        node['template_name'] = RegulationsConfig.custom_tpls.get(
            node['label_id'],
            RegulationsConfig.node_type_tpls[node['node_type']])

        if 'TOC' in node:
            for l in node['TOC']:
                l['label'] = self.section_space(l['label'])

        if 'interp' in node and 'markup' in node['interp']:
            node['interp']['markup'] = self.section_space(
                node['interp']['markup'])

        if node['node_type'] == INTERP:
            self.modify_interp_node(node)

        for c in node['children']:
            self.process_node(c)
Exemplo n.º 3
0
    def process_node(self, node):
        node['label_id'] = '-'.join(node['label'])
        self.process_node_title(node)

        node['html_label'] = to_markup_id(node['label'])
        node['markup_id'] = "-".join(node['html_label'])
        node['tree_level'] = len(node['label']) - 1

        list_level, list_type = self.list_level(
            node['label'], node['node_type'])

        node['list_level'] = list_level
        node['list_type'] = list_type

        if len(node['text']):
            inline_elements = self.inline_applier.get_layer_pairs(
                node['label_id'], node['text'])
            search_elements = self.search_applier.get_layer_pairs(
                node['label_id'])

            if self.diff_applier:
                node['marked_up'] = self.diff_applier.apply_diff(
                    node['text'], node['label_id'])

            layers_applier = LayersApplier()
            layers_applier.enqueue_from_list(inline_elements)
            layers_applier.enqueue_from_list(search_elements)

            if 'marked_up' in node:
                node['marked_up'] = layers_applier.apply_layers(
                    node['marked_up'])
            else:
                node['marked_up'] = layers_applier.apply_layers(node['text'])
            node['marked_up'] = HTMLBuilder.section_space(node['marked_up'])

        node = self.p_applier.apply_layers(node)

        if 'TOC' in node:
            for l in node['TOC']:
                l['label'] = HTMLBuilder.section_space(l['label'])

        if 'interp' in node and 'markup' in node['interp']:
            node['interp']['markup'] = HTMLBuilder.section_space(
                node['interp']['markup'])

        if node['node_type'] == INTERP:
            self.modify_interp_node(node)

        for c in node['children']:
            self.process_node(c)
Exemplo n.º 4
0
    def process_node(self, node):

        node["label_id"] = "-".join(node["label"])
        self.process_node_title(node)

        node["html_label"] = to_markup_id(node["label"])
        node["markup_id"] = "-".join(node["html_label"])
        node["tree_level"] = len(node["label"]) - 1

        list_level = self.list_level(node["label"], node["node_type"])

        node["list_level"] = list_level

        if len(node["text"]):
            inline_elements = self.inline_applier.get_layer_pairs(node["label_id"], node["text"])
            search_elements = self.search_applier.get_layer_pairs(node["label_id"])

            if self.diff_applier:
                node["marked_up"] = self.diff_applier.apply_diff(node["text"], node["label_id"])

            layers_applier = LayersApplier()
            layers_applier.enqueue_from_list(inline_elements)
            layers_applier.enqueue_from_list(search_elements)

            if "marked_up" in node:
                node["marked_up"] = layers_applier.apply_layers(node["marked_up"])
            else:
                node["marked_up"] = layers_applier.apply_layers(node["text"])
            node["marked_up"] = HTMLBuilder.section_space(node["marked_up"])

        node = self.p_applier.apply_layers(node)

        if "TOC" in node:
            for l in node["TOC"]:
                l["label"] = HTMLBuilder.section_space(l["label"])

        if "interp" in node and "markup" in node["interp"]:
            node["interp"]["markup"] = HTMLBuilder.section_space(node["interp"]["markup"])

        if node["node_type"] == INTERP:
            self.modify_interp_node(node)

        for c in node["children"]:
            self.process_node(c)
Exemplo n.º 5
0
    def process_node(self, node):

        node["label_id"] = "-".join(node["label"])
        self.process_node_title(node)

        node["html_label"] = to_markup_id(node["label"])
        node["markup_id"] = "-".join(node["html_label"])
        node["tree_level"] = len(node["label"]) - 1

        list_level, list_type = self.list_level(node["label"], node["node_type"])

        node["list_level"] = list_level
        node["list_type"] = list_type

        if "formatting" in self.search_applier.layers:
            format_layer_data = self.search_applier.layers["formatting"].layer_data
        else:
            format_layer_data = {}

        def is_table(node_label, layer_data):
            if node_label not in layer_data:
                return False
            else:
                for item in layer_data[node_label]:
                    if "table_data" in item:
                        return True
            return False

        if len(node["text"]):
            inline_elements = self.inline_applier.get_layer_pairs(node["label_id"], node["text"])
            search_elements = self.search_applier.get_layer_pairs(node["label_id"])

            if self.diff_applier:
                node["marked_up"] = self.diff_applier.apply_diff(node["text"], node["label_id"])

            layers_applier = LayersApplier()
            layers_applier.enqueue_from_list(inline_elements)
            layers_applier.enqueue_from_list(search_elements)

            if "marked_up" in node:
                node["marked_up"] = layers_applier.apply_layers(node["marked_up"])
            else:
                node["marked_up"] = layers_applier.apply_layers(node["text"])
            node["marked_up"] = HTMLBuilder.section_space(node["marked_up"])

        elif is_table(node["label_id"], format_layer_data):
            # if this is a table, render it anyway
            layers_applier = LayersApplier()
            search_elements = self.search_applier.get_layer_pairs(node["label_id"])
            layers_applier.enqueue_from_list(search_elements)
            if "marked_up" in node:
                node["marked_up"] = layers_applier.apply_layers(node["marked_up"])
            else:
                node["marked_up"] = layers_applier.apply_layers(node["text"])
            node["marked_up"] = HTMLBuilder.section_space(node["marked_up"])

        node = self.p_applier.apply_layers(node)

        if "TOC" in node:
            for l in node["TOC"]:
                l["label"] = HTMLBuilder.section_space(l["label"])

        if "interp" in node and "markup" in node["interp"]:
            node["interp"]["markup"] = HTMLBuilder.section_space(node["interp"]["markup"])

        if node["node_type"] == INTERP:
            self.modify_interp_node(node)

        for c in node["children"]:
            self.process_node(c)