def generate_styled_text(parent: Tag, styled_text: StyledText): if styled_text.style == 'strong': tag_name = 'strong' elif styled_text.style == 'emphasized': tag_name = 'em' elif styled_text.style == 'code': tag_name = 'code' elif styled_text.style == 'deleted': tag_name = 'del' else: tag_name = None if tag_name is not None: styled_tag = append_component_tag(parent, styled_text, tag_name) generate_components(styled_tag, styled_text.contents) else: if styled_text.style == 'double-quote': parent.append_literal('“') generate_components(parent, styled_text.contents) parent.append_literal('”') elif styled_text.style == 'single-quote': parent.append_literal('‘') generate_components(parent, styled_text.contents) parent.append_literal('’') else: raise StxError(f'Not supported style: {styled_text.style}.', styled_text.location)
def generate_literal(parent: Tag, literal: Literal): parent.append_literal(literal.text)