The CachedMetadata projection
parseMetadata in src/metadata/ gives the CachedMetadata Obsidian’s metadata worker posts for a document, built from the remark-parse 8 engine’s tree. It is phase 2 of the project. It equals the worker’s metadata as JSON, key order included, so the two can be compared with JSON.stringify alone.
import { parseMetadata } from '@mnaoumov/obsidian-markdown-parser';
const metadata = parseMetadata('---\ntags: [a]\n---\n# Title [[Note]]\n\n[text](other%20note.md)');// { links: [...], headings: [...], sections: [...], frontmatter: { tags: ['a'] }, frontmatterPosition: {...}, frontmatterLinks: [] }The types in src/metadata/types.ts take the names Obsidian’s API gives them (CachedMetadata, LinkCache, HeadingCache, Pos, Loc and the rest). The one exception is FootnoteReferenceCache, Obsidian’s FootnoteRefCache, renamed by the repository’s lint rules. The field keeps the worker’s name, footnoteRefs.
What the worker does
Section titled “What the worker does”The worker parses the document with Obsidian’s remark-parse 8 and walks the tree. These are its rules, re-expressed from its behaviour and measured against it. Nothing is taken from the app’s bundle.
- Line breaks. The worker parses with Obsidian’s
breaksoption, so a line feed after any spaces in inline content is abreaknode.parseRemarktakes it asshouldReadSoftLineBreaksAsHard, and the projection turns it on. It shows in the text a markdown link shows. - Input. The worker reads the file’s bytes as UTF-8, so a byte order mark at the start is no part of the document and every offset counts from after it.
parseMetadataencodes and decodes its input the same way. - Sections. Each block of the document is a section: its mdast type,
calloutfor a blockquote that opens a callout,commentfor a comment block,yamlfor front matter. The section carries the block’s id when it has one. - Headings. Only headings that are blocks of the document are listed, not those in quotes, lists or footnotes. The text is the source from the start of the heading’s first child to the end of its last, trimmed. Markup, links, block ids and inline footnotes stay as written, and a heading with no content is
''. - Markdown links and images. A link or image whose destination starts with
./or../, or holds no:, is an internal link or an embed. Its link is the destination afterdecodeURI, with no-break spaces made spaces, trimmed and in Unicode normal form C. A link whose destinationdecodeURIrefuses stays a link and is not listed. An image keeps its destination as it is. A link shows the text of its children, and an image shows its alternative text, a size after a|included. - The text of a link’s children. A text node, code span or inline math gives its value, a break gives a line feed, and emphasis, strong, strikethrough and highlights give their children’s text. A tag gives
#name, an internal link its displayed text, and an embed its target. An image gives its embed link when its destination is no URL, or else its alternative text with a size after its last|taken off, or its title. Comments, raw HTML, block ids, footnote references and numbered inline footnotes give nothing. Each node but a break drops one final line feed from its text, and so does the link. - Front matter. The YAML is parsed with
yaml2 and the worker’s options. The worker bundles a 2.x release from 2.6.0 or later, and every release from 2.6.0 to 2.9.1 gives its result on 20,000 fuzzed front matters.frontmatterandfrontmatterPositionare set only when it parses to a value oftypeofobjectthat is no array. A!!binaryvalue is read withatobinto aUint8Array, as the browser build the worker bundles reads it. The Node build makes aBuffer, which accepts whatatobrefuses. - Front matter links. Every string value at any depth that is a whole
[[link]], and every one that is a whole markdown link whose destination is no URL, is listed with its key path, keys and array indexes joined with.. A markdown link there is decoded withdecodeURIbut not normalized, and a destinationdecodeURIrefuses is kept as it is. - Inline footnotes. Before the walk the worker moves the content of each inline footnote into a footnotes section after the document’s blocks. What an inline footnote holds is listed after everything else. The sections end with one of type
textand one of typeelement, at the start of the line after the last block, a block id later taken out of the tree included. Theelementsection takes the last block id the footnotes hold. - Tasks. A task’s checkbox is put first in a list item no paragraph opens, which moves the item’s end.
- Empty fields. Every list the document has nothing for is left out, and so are the block ids when there are none.
frontmatterLinksis kept when it is empty. - Footnote references. Only references whose label has a definition are listed. A label inside a comment is listed as a reference,
[^1]:included, while a definition inside a comment defines nothing. - Footnote definitions. A line that would interrupt a paragraph, such as a heading, a list item, a fence or the next definition, ends a definition only when its whole marker (
#,-, three backticks,[^2]:) lies in the definition’s first 1,024 characters. Past that the line is part of the definition, so a heading after a long definition is not listed and a next definition is lost. A blank line still ends it. - Link reference definitions. A definition’s title may start on a line after a blank line, so a paragraph that is only a quoted or parenthesized phrase becomes the title of the definition above it, and leaves the document. A title left open makes the definition a paragraph.
- Columns that are off. On the line that opens a comment block, every column after the
%%is 2 short, as if the marker were not there. On a callout’s lazy>line inside a list item, every column is 1 past the text. Obsidian renames links at those columns, so renaming a note rewrites the text there wrong.parseMetadatagives the same columns.
Where the worker throws
Section titled “Where the worker throws”The worker throws on two kinds of front matter. It then posts null instead of metadata, and so does parseMetadata:
- a string value that is a markdown link with no destination, such as
[text]()or[text]( ); - up to 1.15.0, an object with a key
hasOwnProperty, which hides the method the worker calls on it. From 1.15.1 on the worker reads such an object like any other.
Releases
Section titled “Releases”parseMetadata(text, { obsidianVersion }) gives the metadata of the worker of that release, and without a version that of 1.15.0. The 1.15.1 worker differs from 1.15.0’s in two ways, measured on the worker oracle on 2026-11-11:
- It posts a field
v: 1on every document, afterblocksand beforefrontmatter, so an empty note gives{ v: 1 }. On 3,712 of the 3,743 worker documents this is the only difference. - A front matter key
hasOwnPropertyno longer makes it throw. 12 worker documents the 1.15.0 worker postednullfor now get metadata, and the other 19 still givenull, since each holds a markdown link with no destination.
With its own version, parseMetadata gives the worker’s metadata on every document of both releases’ worker oracles.
How it is checked
Section titled “How it is checked”- The worker oracle.
scripts/capture/worker-oracle.tsruns the app’s ownworker.jsoffline in a Nodevm, withatobandbtoaas a browser worker has them. It runs on the 47 documents of the conformance corpus, on 3,200 fuzzed documents from eight piece sets: syntax alone, among blocks and lists, and inside quotes, plus headings, markdown links and images, and YAML front matter, on 51 pinned documents the piece sets do not reach: list items and quotes nested in each other, with a tab between quote levels in two of them, a%%inside an internal link’s content, the shapes of the rules above from comments to columns, each first checked on the live app, and a child list indented less than, at and past its parent’s content column (remark-obsidian.md), and on the 445 inputs imported from another parser’s test suites (remark-obsidian.md). It writes each document’s whole metadata, or thenullthe worker posted, tooracle/worker-metadata-obsidian-1.15.1.json.src/oracle/spec/worker-metadata.test.tspinsparseMetadatato every one of them by full JSON equality. - The live app. The same test pins it to the metadata the live app gave for all 674 examples of the spec oracle (
oracle/spec-obsidian-1.15.1.json). - Outside the repository, the same comparison gives 0 differences on 180,000 fuzzed documents from twelve piece sets, among them 27,435 with parsed front matter, 33,868 that list a markdown link or image, and 999 the worker posts
nullfor. It gives 0 too on the 41,875 documents the oracle files then held. src/metadata/metadata.test.tspins the rules above one by one.