I am developing a plugin for obsidian inspired by the obsidian-todotxt-codeblocks plugin. For that I need to get the line where a codeblock is located. I tried to use 'editor.posAtDom(el)' for each codeblock, but get a RangeError. As this is working for teh obsidian-todotxt plugin, what am I missing?
My Code:
export default class MyPlugin extends Plugin {
async onload() {
await this.loadSettings();
console.log("loaded settings");
this.registerMarkdownCodeBlockProcessor("pergament", (source, el, ctx) => {
console.log("registered markdown code processor");
const text = document.createElement("div");
text.innerHTML = source;
text.id = "pergament";
el.appendChild(text);
console.log(el);
const markDownView: MarkdownView | null = this.app.workspace.getActiveViewOfType(MarkdownView)
if (markDownView) {
console.log("markdownView exists");
const editorView: EditorView = markDownView.editor.cm as EditorView;
console.log(editorView.scrollDOM);
const pos = editorView.posAtDOM(el);
const line = editorView.state.doc.lineAt(pos);
}
})
}
}