obsidian-annotator icon indicating copy to clipboard operation
obsidian-annotator copied to clipboard

[Feature Request] Allow internal [[wiki-links]] as annotation-target links ?

Open born2discover opened this issue 1 year ago • 0 comments

Would it be possible to allow for annotation-target link to be a wiki-link ?

For example:

---
annotation-target: [[some/folder/file.pdf]]
---

That would allow Obsidian to automatically update the link whenever the file path changes (as seems to be requested by #292) and would simplify the overall work-flow for vanilla use cases.

From my poking around the source, it seems the change would only require changes to getAnnotationTarget function in annotatorView.tsx:

getAnnotationTarget(file: TFile): string {
    const annotationTargetPropertyValue = this.plugin.getPropertyValue(ANNOTATION_TARGET_PROPERTY, file);

    if (!annotationTargetPropertyValue) {
        this.plugin.log('Invalid annotation target!');
        return '';
    }

    for (let target of [
        annotationTargetPropertyValue,
        `${this.plugin.settings.customDefaultPath}${annotationTargetPropertyValue}`
    ])
    {
        //unpack target if it is is an array (For Metaedit compatability)
        if (Array.isArray(target)) {
            target = target[0];
        }

        if (isUrl(target)) {
            return target;
        }

        let destFile: TFile;
        try {
            destFile = this.app.metadataCache.getFirstLinkpathDest(target, file?.path || '');
        } finally {
            if (destFile) {
                return destFile.path;
            }
        }
    }
}

Unfortunately I am not a TypeScript developer, nor am I familiar with inner workings of Obsidian or Annotator to attempt an implementation myself.

born2discover avatar May 09 '23 15:05 born2discover