mdelobelle / obsidian_supercharged_links

obsidian plugin to add attributes and context menu options to internal links
MIT License
537 stars 35 forks source link

Add Option to Disable `a.internal-links` (i.e. Table Elements) for Supercharged Links #237

Open RicSanOP opened 2 weeks ago

RicSanOP commented 2 weeks ago

I love using this plugin to add some color and context to my live editor and side interfaces in obsidian. However, having supercharged links in tables and dataview tables simply adds too much bloat. Currently I simply customized the plugin code (as seen below) to disable rendering on a.internal-link elements. I would recommend an option in settings for toggling this ability in case anyone else might appreciate this.

// to prevent rendering on a.internal-links comment out and replace with empty list the following
// the rest of the options (i.e. live preview and interface panels) still work fine
// this means tables won't get bloated with supercharged links
function updateElLinks(app, plugin, el, ctx) {
    const settings = plugin.settings;
    //const links = el.querySelectorAll('a.internal-link');
    const links = []
    const destName = ctx.sourcePath.replace(/(.*).md/, "$1");
    links.forEach((link) => {
        updateLinkExtraAttributes(app, settings, link, destName);
    });
}
function updateVisibleLinks(app, plugin) {
    const settings = plugin.settings;
    app.workspace.iterateRootLeaves((leaf) => {
        if (leaf.view instanceof obsidian.MarkdownView && leaf.view.file) {
            const file = leaf.view.file;
            const cachedFile = app.metadataCache.getFileCache(file);
            if (cachedFile.links) {
                cachedFile.links.forEach((link) => {
                    const fileName = file.path.replace(/(.*).md/, "$1");
                    const dest = app.metadataCache.getFirstLinkpathDest(link.link, fileName);
                    if (dest) {
                        const new_props = fetchTargetAttributesSync(app, settings, dest, false);
                        //const internalLinks = leaf.view.containerEl.querySelectorAll(`a.internal-link[href="${link.link}"]`);
                        const internalLinks = []
                        internalLinks.forEach((internalLink) => setLinkNewProps(internalLink, new_props));
                    }
                });
            }
        }
    });
}