note_splitter.formatter_ module
For changing some important details in Section tokens before output.
The Formatter class’ callable normalizes header levels, adds frontmatter and global tags to each section, and then converts the section tokens to strings.
- class note_splitter.formatter_.Formatter
Bases:
object
Creates a Callable that prepares sections for output.
The callable normalizes header levels, adds frontmatter and global tags to each section, and then converts the section tokens to strings.
- __call__(sections: list[note_splitter.tokens.Section], global_tags: list[str], copy_global_tags: bool, copy_frontmatter: bool, move_footnotes: bool, frontmatter: Optional[object] = None, footnotes: Optional[list[note_splitter.tokens.Footnote]] = None) list[str]
Formats sections for output.
- Parameters
sections (list[tokens.Section]) – The sections to format.
global_tags (list[str]) – The global tags to add to each section.
frontmatter (object | None, optional) – The frontmatter to add to each section.
footnotes (list[tokens.Footnote] | None, optional) – The footnotes to add to each section with the respective footnote reference.
- get_section_title(section: note_splitter.tokens.Section) str
Gets the title of a section.
The title is the body of the first header, or the first Text token’s content if there is no header, or a random string if the section is empty.
- Parameters
section (tokens.Section) – The section to get the title of.
- insert_global_tags(global_tags: list[str], section: note_splitter.tokens.Section) None
Inserts the global tags into a section.
- Parameters
global_tags (list[str]) – The global tags to add to the section.
section (tokens.Section) – The section to insert the global tags into.
- move_footnotes(footnotes: list[note_splitter.tokens.Footnote], section: note_splitter.tokens.Section) None
Moves footnotes to sections with the relevant references.
- Parameters
footnotes (list[tokens.Footnote]) – The footnotes to add to the section if it contains references to them, or to remove from the section if it does not contain references to them.
section (tokens.Section) – The section to append/remove the footnotes to/from.
- normalize_headers(section: note_splitter.tokens.Section) str
Normalizes the markdown header levels in a section.
- Parameters
section (tokens.Section) – The section to normalize.
- Returns
The title of the section.
- Return type
str
- prepend_frontmatter(frontmatter: object | None, section_title: str, section: note_splitter.tokens.Section) None
Prepends the frontmatter to a section as a Text object.
- Parameters
frontmatter (object | None) – The frontmatter to add to the section. If None, the function will immediately return.
section_title (str) – The title of the section.
section (tokens.Section) – The section to prepend the frontmatter to.
- note_splitter.formatter_.footnote_referenced_in_section(footnote: note_splitter.tokens.Footnote, section: note_splitter.tokens.Section) bool
Checks if a footnote is referenced in a section.
- Parameters
footnote (tokens.Footnote) – The footnote to search for a reference to.
section (tokens.Section) – The section to search in.
- Returns
Whether the footnote is referenced in the section.
- Return type
bool