Quickadd question - import of Obsidian components

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];
}

I found a solution for my problem:

I created an own plugin and with the following code i got the rendered note how i wanted it. It just has the drawback that it is an own plugin and i need to remove the HTML-tags around it by “hand”:

		this.addCommand({
			id: 'get-html',
			name: 'Get HTML',
			callback: async () => {
				const currentFile = this.app.workspace.getActiveFile();
                if (!currentFile) {
                    return;
                }

                // Read current file content
                const currentContent = await this.app.vault.read(currentFile);
				
				const container = document.createElement('div');
				await MarkdownRenderer.render(this.app, currentContent, container, currentFile.path, this);
				const html = container.innerHTML;

				console.log(html);
			}
		});

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.