Hey guys,
i have a question regarding the mentioned QuickAdd plugin: I am currently using it to convert Obsidian notes to OneNote via their API. The problem for me is gathering the contents of the linked documents. So is there somehow a function which i could use to get the Reading view (HTMLView?) of my documents, which i get when i click on the book at the top right?
I already found the MarkdownRenderer-cass, but i am not able to use them in my QuickAdd-Javascript. Theoretically i just want to do something like here, but the import of the Obsidian components is the problem.
Currently i build all the links myself with this code:
async function extractNoteContent(filePath) {
const fileContent = await app.vault.read(filePath);
const frontmatter = app.metadataCache.getFileCache(filePath)?.frontmatterPosition;
if (!frontmatter) {
console.error(`No frontmatter found in ${filePath.path}.`);
return fileContent;
}
let end = frontmatter.end.line + 1
extractedContent = fileContent.split("\n").slice(end).join("\n")
console.log(`Content extracted from ${filePath.path}: ${extractedContent}`);
return extractedContent;
}
async function processCurrentNote(activeFile) {
const noteContent = await extractNoteContent(activeFile);
if (!noteContent) return;
const linkPattern = /!\[\[([^\]]+)\]\]/g;
const links = {};
let match;
while ((match = linkPattern.exec(noteContent)) !== null) {
const noteLink = match[1];
const [noteFileName, heading] = noteLink.split("#");
const noteFile = app.metadataCache.getFirstLinkpathDest(
noteFileName,
activeFile.path
);
if (noteFile) {
const linkedNoteContent = await extractNoteContent(noteFile);
links[`![[${noteLink}]]`] = linkedNoteContent;
}
}
return [noteContent, links];
}