Skip to content

obsidian/functions/getFrontMatterInfo

Mock of Obsidian’s getFrontMatterInfo.

A port of Obsidian’s own implementation (1.14.x app.js, hg), not an approximation of it. Two of its habits are easy to get wrong:

  • frontmatter INCLUDES the newline that ends the last property line, and to is the index of the closing --- itself. So [from, to) is exactly the region a caller replaces, and splicing in text that ends in a newline - which stringifyYaml always does - leaves no blank line before the closing delimiter. - The closing --- is searched for from the start of the line after the opening one, so an EMPTY block (---\n---\n) exists, with frontmatter the empty string.
Function Description
getFrontMatterInfo Locates the frontmatter block at the start of a file’s contents: whether it exists, its text, the offsets where that text starts and ends, and the offset where the body after the closing --- begins.