from fastcore.test import *
from trouver.helper import _test_directory
markdown.obsidian.personal.information_notes
Look in See Also section
The see also section of a standard information note contains bulleted lists of links to related notes.
These related notes include common terms notes and notation notes.
bulleted_links_of_type_in_section
bulleted_links_of_type_in_section (info_note:trouver.markdown.obsidian.v ault.VaultNote, vault:os.PathLike, section:str, note_type:Optional[trouve r.markdown.obsidian.personal.note_type .PersonalNoteTypeEnum]=None)
Returns a list of [
ObsidianLink](https://hyunjongkimmath.github.io/trouver/markdown.obsidian.links.html#obsidianlink)
s of notes of the given type listed in the specified section of the standard information note.
Parameters - info_note
- VaultNote - Name of the information note. - vault
- PathLike - Path to the vault directory. - section
- str - Title of the section - note_type
- trove.markdown.obsidian.personal.note_type.PersonalNoteTypeEnum
or None
- The type of the notes to include in the list. If None
, then all note types are included. Defaults to None
.
Returns - list of markdown.obsidian.links.ObsidianLink
objects - Each entry is the name of a notation note in the vault.
Raises - AssertionError - If the note is not a standard information note
# TODO: test
Standard information notes in See Also Section
links_to_common_terms_notes_in_see_also_section
links_to_common_terms_notes_in_see_also_section (info_note:trouver.markd own.obsidian.vault.Vault Note, vault:os.PathLike)
Returns a list of names of common terms notes listed in the See Also
section of the standard information note.
Parameters - info_note
- VaultNote - vault
- Pathlike - Path to the vault directory.
Returns - list[str] - Each entry is the name of a notation note in the vault.
# TODO: examples
Get the main content of the Standard information note
main_content
main_content (note:trouver.markdown.obsidian.vault.VaultNote)
The main content of the standard information note.
This is the text not in the yaml frontmatter and not the '#See Aslo'
section and below.
Parameters - note: VaultNote - A standard information note.
Returns - str
Identify reference that the information note belongs to
Each information note tends to “come from” a reference. The following is a function to identify which reference the information note comes from.
reference_of_information_note
reference_of_information_note (note:trouver.markdown.obsidian.vault.Vaul tNote)
Returns the reference note that the information note probably comes from.
TODO
Parameters - note
- VaultNote - A standard information note
Returns - VaultNote
reference_notes_in_references_section_of_information_note
reference_notes_in_references_section_of_information_note (note:trouver. markdown.obsid ian.vault.Vaul tNote)
Returns a list of [
ObsidianLink](https://hyunjongkimmath.github.io/trouver/markdown.obsidian.links.html#obsidianlink)
objects corresponding to reference notes in the “References” section of the information note.
Parameters - note
- VaultNote - A standard information note
Returns - list of [
ObsidianLink](https://hyunjongkimmath.github.io/trouver/markdown.obsidian.links.html#obsidianlink)
# TODO: examples
Note creation
I think that one of the things that takes me a lot of time while making my math vault is the following process: 1. Creating notes 2. Inserting the template 3. Filling in the note 4. Renaming the note and its title 5. Linking the note to the appropriate index note.
Creating notes and linking them to the index note
Here, I will address 1, 2, and 5; 1 can be done with the [
VaultNote](https://hyunjongkimmath.github.io/trouver/markdown.obsidian.vault.html#vaultnote)
class. Then, fill in the blank notes with a template and then link them to the appropriate index note
When creating/filling in the note, it can be useful to add tags. For example, I can add a tag to indicate that the note was autogenerated.
citation_location_string
citation_location_string (citation_location:tuple[str,int])
Formats a pair specifying the Numbering label and page
Parameters - citation_location
- 2-tuple or empty tuple - Consists of a label str and a page number indicating where in the note’s reference text the note’s information originates from, e.g. the label might be the str ‘Theorem 1.2.3’ and the page number might be the int 85.
fill_info_note_with_template
fill_info_note_with_template (vn:trouver.markdown.obsidian.vault.VaultNo te, template:trouver.markdown.obsidian.vaul t.VaultNote, citation_location:tuple[str,int]=(), content:str='', tags_to_add:Union[str,list[ str],tuple[str],NoneType]=None)
Fills in the note with a template with optionally tags.
Current implementation adds content to line 5 of the note.
Parameters - vn
- [
VaultNote](https://hyunjongkimmath.github.io/trouver/markdown.obsidian.vault.html#vaultnote)
- template
- [
VaultNote](https://hyunjongkimmath.github.io/trouver/markdown.obsidian.vault.html#vaultnote)
- citation_location
- 2-tuple or empty tuple - Consists of a label str and a page number indicating where in the note’s reference text the note’s information originates from, e.g. the label might be the str ‘Theorem 1.2.3’ and the page number might be the int 85. - content
- str - Content to add to the note. Defaults to the empty str. - tags_to_add
- str or list of str or tuple of str or None
- Each str is just the name of the tag without the leading hashtag. Defaults to None
, in which case no tags are added.
link_info_notes_to_index
link_info_notes_to_index (info_notes, index_note:trouver.markdown.obsidian.vault.Vaul tNote, citation_locations:tuple=(), insert_blank_line=False)
Links notes to an index_note.
For now, just adds to the bottom of the thing # TODO Make it possible to add in specific sections
Parameters - info_notes - [
VaultNote](https://hyunjongkimmath.github.io/trouver/markdown.obsidian.vault.html#vaultnote)
or list of [
VaultNote](https://hyunjongkimmath.github.io/trouver/markdown.obsidian.vault.html#vaultnote)
- index_note - [
VaultNote](https://hyunjongkimmath.github.io/trouver/markdown.obsidian.vault.html#vaultnote)
- insert_blank_line - bool - If True
, then insert a blank line at the end of the index note before adding the links to the info notes.
create_info_notes_and_link_to_index
create_info_notes_and_link_to_index (to_create:list[trouver.markdown.obs idian.vault.VaultNote], template:tro uver.markdown.obsidian.vault.VaultNo te, index_note:trouver.markdown.obsi dian.vault.VaultNote, citation_locations:list=[], content_to_add:list=[], tags_to_add: Union[str,list[str],tuple[str],NoneT ype]=None)
Creates multiple notes, fills them in with a template, and links them to the appropriate index note.
Current implementation adds content from content_to_add
to line 5 of the VaultNotes.
Parameters - to_create
- list of [
VaultNote](https://hyunjongkimmath.github.io/trouver/markdown.obsidian.vault.html#vaultnote)
. - template
- [
VaultNote](https://hyunjongkimmath.github.io/trouver/markdown.obsidian.vault.html#vaultnote)
- index_note
- [
VaultNote](https://hyunjongkimmath.github.io/trouver/markdown.obsidian.vault.html#vaultnote)
- citation_locations
- list of 2-tuples or empty tuples - Each tuple consists of a label str and a page number indicating where in the note’s reference text the note’s information originates from, e.g. the label might be the str ‘Theorem 1.2.3’ and the page number might be the int 85. This list must be of the same length as to_create
. - content_to_add
- list of str - Each str is the content to be added for each note in to_create
. Defaults to the empty list, in which case no content is added. - tags_to_add
- str or list of str or tuple of str or None
- Each str is just the name of the tag without the leading hashtag. Defaults to None
, in which case no tags are added.
create_generic_info_notes_and_link_to_index
create_generic_info_notes_and_link_to_index (reference:str, count:int, vault, subdirectory, templat e:trouver.markdown.obsidian. vault.VaultNote, index_note: trouver.markdown.obsidian.va ult.VaultNote, tags_to_add=None)
Creates generically named notes, fills them in with a template, and links them to the appropriate index note.
The note will be named in the form f'{reference}_{number}'
, where number
starts with 0.
Parameters - reference
- str - The name of the reference. This will be part of the generic note names. - count
- int - The number of generic info notes to create. - vault
- Pathlike - subdirectory
- Pathlike - The subdirectory in vault
to create the notes in. - template
- VaultNote - index_note
- VaultNote - tags_to_add - str or list of str or tuple of str or None
- Each str is just the name of the tag without the leading hashtag. Defaults to None
, in which case no tags are added.
Getting an index note
index_note_of_a_directory
index_note_of_a_directory (vault:os.PathLike, directory:os.PathLike)
Return the index note in a directory in an Obsidian.md
vault, if it exists.
Assumes that the directory has at most one index note.
Raises
- RuntimeError
- If more than one index note exists in the directory.
Type | Details | |
---|---|---|
vault | PathLike | |
directory | PathLike | Relative to vault |
Returns | typing.Optional[trouver.markdown.obsidian.vault.VaultNote] | Either the index note in the directory if it exists or None |
# TODO: examples
= _test_directory() / 'test_vault_5'
vault
= index_note_of_a_directory(vault, directory='algebra')
sample_output assert sample_output is not None
'_index_algebra')
test_eq(sample_output.name,
= index_note_of_a_directory(vault, directory='')
sample_output assert sample_output is not None
'_index') test_eq(sample_output.name,
If there is more than one index note in a directory, then a RuntimeError
is raised:
= _test_directory() / 'test_vault_5'
vault
with ExceptionExpected(RuntimeError):
= index_note_of_a_directory(vault, directory='folder_with_more_than_one_index_note') sample_output
index_note_of_note
index_note_of_note (note:trouver.markdown.obsidian.vault.VaultNote)
Return the index note indexing the specified note.
note
is assumed to either be an information note or itself an index note.
Assumes that a note in indexed in at most one index note and that this index note is either in the same directory as the note or in the immediate parent directory of the note.
Raises
- UserWarning
- If an index note that is supposed to index
note
exists, but does not actually indexnote
.
- If an index note that is supposed to index
Type | Details | |
---|---|---|
note | VaultNote | An information note or an index note |
Returns | typing.Optional[trouver.markdown.obsidian.vault.VaultNote] | The index note which indexes note . If no such index note exists (in either the same directory as or the immediate parent directory of the note), then None is returned. In particular, None is returned if note is the root index note of the vault. |
# TODO: examples
= _test_directory() / 'test_vault_5'
vault
# The index note is in the parent directory of the directory that `info_note` is in.
= VaultNote(vault, name='number_theory_reference_1_Definition 1.1')
info_note = index_note_of_note(info_note)
sample_output assert sample_output is not None
'_index_1_chapter_number_theory_reference_1')
test_eq(sample_output.name,
# Here, we have an `index_note` and we are trying to find its index note, which is
# in the parent directory of the directory that `index_note` is in.
= VaultNote(vault, name='_index_1_chapter_number_theory_reference_1')
index_note = index_note_of_note(index_note)
sample_output assert sample_output is not None
'_index_number_theory_reference_1')
test_eq(sample_output.name,
# Here, we have the `root_index_note` of the vault, which is in the root directory
# of the vault. This root index note does not have an index note.
= VaultNote(vault, name='_index')
root_index_note = index_note_of_note(root_index_note)
sample_output assert sample_output is None
# Here, we have `info_note` that is in the same directory as its index note.
= VaultNote(vault, name='number_theory_reference_1_note_in_same_directory_as_index_note')
info_note = index_note_of_note(info_note)
sample_output assert sample_output is not None
'_index_2_chapter_number_theory_reference_2') test_eq(sample_output.name,
AssertionError: