Hello, I am trying to find a way to get a note as structured data, ideally using native obsidian API.
With structured I mean nested data: sections containing lists, and lists containing items, a separate key with metadata etc.
I don’t want to parse markdown myself because I don’t want to track changes to the format or edge cases.
Thanks
getFileCache and getCache
app.metadataCache.getFileCache(file: TFile): CachedMetadata | null;
app.metadataCache.getCache(path: string): CachedMetadata | null;
They return the metadata of a note. This means the frontmatter, headings and sections. It looks like this:
{
"headings": [
{
"position": {
"start": {
"line": 6,
"col": 0,
"offset": 94
},
"end": {
"line": 6,
"col": 9,
"offset": 103
}
},
"heading": "Visitas",
"level": 1
}
],
"sections": [
{
"type": "yaml",
"position": {
"start": {
"line": 0,
"col": 0,
"offset": 0
},
"end": {
"line": 5,
"col": 3,
"offset": 93
}
}
},
{
"type": "heading",
"position": {
"start": {
"line": 6,
"col": 0,
"offset": 94
},
"end": {
"line": 6,
"col": 9,
"offset": 103
}
}
}
],
"frontmatter": {
"tags": [
"restaurant",
"place/POI"
],
"score": {
"{ value:score }": null
},
"created": "2023-08-29",
"location": [],
"position": {
"start": {
"line": 0,
"col": 0,
"offset": 0
},
"end": {
"line": 5,
"col": 3,
"offset": 93
}
}
}
}