def set_title_layout_block(self, title_block: LayoutBlock): self.set_child_element_at( ['teiHeader', 'fileDesc', 'titleStmt'], TEI_E('title', { 'level': 'a', 'type': 'main' }, *iter_layout_block_tei_children(title_block)))
def get_tei_child_elements_for_semantic_content( semantic_content: SemanticContentWrapper, context: TeiElementFactoryContext ) -> List[etree.ElementBase]: semantic_type = type(semantic_content) element_factory = ELEMENT_FACTORY_BY_SEMANTIC_CONTENT_CLASS.get( semantic_type ) if element_factory is not None: return element_factory.get_tei_children_for_semantic_content( semantic_content, context=context ) parsed_tag_expression = PARSED_TAG_EXPRESSION_BY_SEMANTIC_CONTENT_CLASS.get( semantic_type ) if parsed_tag_expression: if ( isinstance(semantic_content, SemanticOptionalValueSemanticMixedContentWrapper) and semantic_content.value is not None ): return [parsed_tag_expression.create_node( get_default_attributes_for_semantic_content(semantic_content), semantic_content.value, element_maker=TEI_E )] return [parsed_tag_expression.create_node( *iter_layout_block_tei_children(semantic_content.merged_block), element_maker=TEI_E )] return [get_tei_note_for_semantic_content(semantic_content)]
def iter_layout_block_tei_children( self, layout_block: LayoutBlock, enable_coordinates: bool = True ) -> Iterable[Union[str, etree.ElementBase]]: return iter_layout_block_tei_children( layout_block, enable_coordinates=enable_coordinates )
def test_should_add_superscript_text(self): block = LayoutBlock.for_tokens([ LayoutToken(TOKEN_1), LayoutToken(TOKEN_2, font=SUPERSCRIPT_FONT_1), LayoutToken(TOKEN_3) ]) node = TEI_E.node(*iter_layout_block_tei_children(block)) assert get_tei_xpath_text_content_list( node, './tei:hi[@rend="superscript"]') == [TOKEN_2] assert get_text_content(node) == ' '.join([TOKEN_1, TOKEN_2, TOKEN_3])
def test_should_add_bold_and_italics_text(self): block = LayoutBlock.for_tokens([ LayoutToken(TOKEN_1), LayoutToken(TOKEN_2, font=BOLD_ITALICS_FONT_1), LayoutToken(TOKEN_3) ]) node = TEI_E.node(*iter_layout_block_tei_children(block)) LOGGER.debug('xml: %r', etree.tostring(node)) assert get_tei_xpath_text_content_list( node, './/tei:hi[@rend="bold"]') == [TOKEN_2] assert get_tei_xpath_text_content_list( node, './/tei:hi[@rend="italic"]') == [TOKEN_2] assert get_text_content(node) == ' '.join([TOKEN_1, TOKEN_2, TOKEN_3])
def get_tei_children_and_whitespace_for_semantic_content( semantic_content: SemanticContentWrapper, context: TeiElementFactoryContext ) -> Tuple[List[Union[dict, str, etree.ElementBase]], str]: layout_block = semantic_content.merged_block if isinstance(semantic_content, SemanticTextContentWrapper): return ( list(iter_layout_block_tei_children(layout_block)), layout_block.whitespace ) return ( get_tei_child_elements_for_semantic_content( semantic_content, context=context ), layout_block.whitespace )
def set_abstract_layout_block(self, abstract_block: LayoutBlock): self.set_child_element_at( ['teiHeader', 'profileDesc', 'abstract'], TEI_E('p', *iter_layout_block_tei_children(abstract_block)))
def add_content(self, layout_block: LayoutBlock): if self._pending_whitespace: extend_element(self.element, [self._pending_whitespace]) self._pending_whitespace = layout_block.whitespace extend_element(self.element, iter_layout_block_tei_children(layout_block))