def test_get_tags_from_contents_no_tags_in_content(self, processing_options, conversion_settings): contents = [ Paragraph(processing_options, [TextItem(processing_options, 'some text')]), Paragraph(processing_options, [TextItem(processing_options, 'some more text')]), Paragraph(processing_options, [TextItem(processing_options, 'even more text')]), ] note = NimbusNote(processing_options, contents, conversion_settings, 'My Note') expected = set() result = note.get_tags_from_contents() assert result == expected
def test_get_tags_from_contents(self, processing_options, conversion_settings): contents = [ Paragraph(processing_options, [TextItem(processing_options, '#tag1')]), Paragraph(processing_options, [TextItem(processing_options, '#tag2')]), Paragraph(processing_options, [TextItem(processing_options, 'some text')]), ] note = NimbusNote(processing_options, contents, conversion_settings, 'My Note') expected = {'#tag1', '#tag2'} result = note.get_tags_from_contents() assert result == expected
def test_note_markdown(self, processing_options, conversion_settings): contents = [ Paragraph(processing_options, [TextItem(processing_options, '#tag1')]), Paragraph(processing_options, [TextItem(processing_options, '#tag2')]), Paragraph(processing_options, [TextItem(processing_options, 'some text')]), ] note = NimbusNote(processing_options, contents, conversion_settings, 'My Note') expected = '#tag1\n#tag2\nsome text\n' result = note.markdown() assert result == expected
def test_note_html(self, processing_options, conversion_settings): contents = [ Paragraph(processing_options, [TextItem(processing_options, '#tag1')]), Paragraph(processing_options, [TextItem(processing_options, '#tag2')]), Paragraph(processing_options, [TextItem(processing_options, 'some text')]), ] note = NimbusNote(processing_options, contents, conversion_settings, 'My Note') expected = '<!doctype html><html lang="en"><p>#tag1</p><p>#tag2</p><p>some text</p></html>' result = note.html() assert result == expected
def extract_from_nimbus_bookmark(tag, processing_options: NimbusProcessingOptions): if tag.name != 'div' or not tag.get( 'class') or 'nimbus-bookmark' not in tag['class']: return a_tag = tag.find('a') items = [] if a_tag: href = a_tag['href'] text_tag = tag.find('div', class_='nimbus-bookmark__info__name') display_text = text_tag.text link_object = Hyperlink(processing_options, display_text, href) items.append(link_object) description_tag = tag.find('div', class_="nimbus-bookmark__info__desc") if description_tag: description_object = TextItem(processing_options, description_tag.text) items.append(description_object) image_div_tag = tag.find("div", class_="nimbus-bookmark__preview") if image_div_tag: image_tag = image_div_tag.find('img') if image_tag: image_data_object = html_data_extractors.extract_from_img_tag( image_tag, processing_options) image_data_object.width = "280" # match max width size in nimbus css items.append(image_data_object) return Paragraph(processing_options, items)
def extract_from_div(div_tag, processing_options: ProcessingOptions, note_specific_tag_cleaning: Optional[Callable] = None): if div_tag.name != 'div': return items = [] all_children = [child for child in div_tag.children if is_a_tag(child)] # child_items = process_child_items(div_tag, processing_options, note_specific_tag_cleaning) child_items = process_child_items(div_tag, processing_options, note_specific_tag_cleaning) items = helper_functions.merge_iterable_or_item_to_list(items, child_items) items = list(items) # stop multiple child divs creating multiple empty paragraphs if len(all_children) == 1 and all_children[0].name == 'div': return items # stop multiple child divs creating multiple empty paragraphs if len(items): if isinstance(items[0], Paragraph): return items return Paragraph(processing_options, items)
def test_embed_nimbus_markdown_output(self, processing_options): embed_caption = Paragraph(processing_options, [TextItem(processing_options, 'caption')]) contents = BlockQuote(processing_options, [TextItem(processing_options, 'some html')]) item = EmbedNimbus(processing_options, contents, embed_caption) result = item.markdown() assert result == '> some html\n\ncaption\n\n'
def test_embed_nimbus_html_output(self, processing_options): embed_caption = Paragraph(processing_options, [TextItem(processing_options, 'caption')]) contents = BlockQuote(processing_options, [TextItem(processing_options, 'some html')]) item = EmbedNimbus(processing_options, contents, embed_caption) result = item.html() assert result == '<p><blockquote>some html</blockquote>/p><p>caption</p>'
def test_find_tags_stop_when_not_a_paragraph_or_title_item(self, processing_options, conversion_settings): contents = [ Head(processing_options, [TextItem(processing_options, 'title')]), Body(processing_options, [ Paragraph(processing_options, [TextItem(processing_options, '#tag1/tag3')]), Paragraph(processing_options, [TextItem(processing_options, '#tag2')]), TextItem(processing_options, 'my title'), ] ) ] note = NimbusNote(processing_options, contents, conversion_settings, 'My Note') note.find_tags() assert set(note.tags) == {'tag1', 'tag2', 'tag3'}
def test_find_tags_do_not_split_tags(self, processing_options, conversion_settings): contents = [ Head(processing_options, [TextItem(processing_options, 'title')]), Body(processing_options, [ Paragraph(processing_options, [TextItem(processing_options, '#tag1/tag3')]), Paragraph(processing_options, [TextItem(processing_options, '#tag2')]), TextItem(processing_options, 'my title'), ] ) ] conversion_settings.split_tags = False note = NimbusNote(processing_options, contents, conversion_settings, 'My Note') note.find_tags() assert set(note.tags) == {'tag1/tag3', 'tag2'}
def extract_from_nimbus_button(div_tag, processing_options: NimbusProcessingOptions): if not div_tag.name == 'div' or not div_tag.get( 'class') or 'button-single' not in div_tag['class']: return button_tag = div_tag.find('nimbus-button') if button_tag: # set class to inline-button to reuse the inline-button extract button_tag.attrs['class'] = ['inline-button'] hyperlink = extract_from_nimbus_inline_button(button_tag, processing_options) return Paragraph(processing_options, [hyperlink])
def test_add_front_matter_to_content(self, processing_options, conversion_settings): contents = [ Head(processing_options, [TextItem(processing_options, 'title')]), Body(processing_options, [ Paragraph(processing_options, [TextItem(processing_options, '#tag1/tag3')]), Paragraph(processing_options, [TextItem(processing_options, '#tag2')]), TextItem(processing_options, 'my title'), ] ) ] conversion_settings.split_tags = False note = NimbusNote(processing_options, contents, conversion_settings, 'My Note') note.find_tags() note.add_front_matter_to_content() expected = '---\ngenerator: YANOM\ntag:\n- tag1/tag3\n- tag2\ntitle: My Note\n---\n\ntitle\n\nmy title' result = note.markdown() assert result == expected
def test_find_tags_keep_tag_content_with_more_than_tag_on_it(self, processing_options, conversion_settings): contents = [ Head(processing_options, [TextItem(processing_options, 'title')]), Body(processing_options, [ Paragraph(processing_options, [TextItem(processing_options, '#tag1/tag3')]), Paragraph(processing_options, [TextItem(processing_options, '#tag2'), TextItem(processing_options, ' extra content on tag line') ] ), TextItem(processing_options, 'my title'), ] ) ] note = NimbusNote(processing_options, contents, conversion_settings, 'My Note') note.find_tags() expected = 'title\n#tag2 extra content on tag line\nmy title' assert note.markdown() == expected