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 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 test_match_link_to_mention_text_different_folder_as_note( self, processing_options, conversion_settings): mention = MentionNote(processing_options, 'my-mention-note', 'ws-1234', 'note-5678') # Mention note is the note this link links to mention_note = NimbusNote(processing_options, contents=[], conversion_settings=conversion_settings) mention_note.title = 'my-mention-note' mention_note_paths = NotePaths() # mention_note_paths.path_to_source_workspace = Path('source/workspace') # mention_note_paths.path_to_target_folder = Path('target') mention_note_paths.path_to_source_folder = Path('source') mention_note_paths.path_to_note_target = Path( 'target/workspace/mention_note_folder') mention_note.note_paths = mention_note_paths dict_of_notes = {'my-mention-note': [mention_note]} # this is the note the mention link is in this_note_note_paths = NotePaths() this_note_note_paths.path_to_source_folder = Path('source') this_note_note_paths.path_to_target_folder = Path('target') this_note_note_paths.path_to_note_source = Path( 'source/workspace/this_note_folder') this_note_note_paths.path_to_note_target = Path( 'target/workspace/this_note_folder') nimbus_ids = NimbusIDs() mention.match_link_to_mention_text(nimbus_ids, dict_of_notes, this_note_note_paths) assert mention.target_path == { Path('../mention_note_folder/my-mention-note.md') } assert len(nimbus_ids.notes) == 1 assert len(nimbus_ids.workspaces) == 1
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
def initialise_new_note(zip_file, conversion_settings, processing_options: NimbusProcessingOptions): new_note = NimbusNote(processing_options, contents=[], conversion_settings=conversion_settings) new_note.title = zip_file.stem.replace('_', ' ') new_note.note_paths.path_to_note_source = Path(zip_file.parent) new_note.note_paths.path_to_source_folder = conversion_settings.source_absolute_root dirty_workspace_folder_name = Path(zip_file.parent).relative_to( conversion_settings.source_absolute_root).parts[0] new_note.note_paths.path_to_source_workspace = Path( conversion_settings.source_absolute_root, dirty_workspace_folder_name) new_note.note_paths.path_to_target_folder = conversion_settings.export_folder_absolute new_note.note_paths.note_target_suffix = get_file_suffix_for( conversion_settings.export_format) new_note.note_paths.note_source_file_name = zip_file.name clean_file_name = helper_functions.generate_clean_filename( new_note.title, processing_options.filename_options) new_note.note_paths.note_target_file_name = Path( f'{clean_file_name}' f'{new_note.note_paths.note_target_suffix}') new_note.note_paths.set_note_target_path(processing_options) new_note.note_paths.set_path_to_attachment_folder( conversion_settings.attachment_folder_name, processing_options) return new_note
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