Displaying only the header name in links to headers

I thought I would share a quick work around to change the format of how header links are shown in preview from [[note > header]] to [[header]] or any other format. If there is a better way to do it, please let me know:

onload() {
    let postProc: MarkdownPostProcessor;

	postProc = (el: HTMLElement, ctx: MarkdownPostProcessorContext) => {

	    var linkElements = el.getElementsByClassName("internal-link");
	    var barIndex, alias;
	    for(var i = 0; i < linkElements.length; i++) {
		    barIndex = (linkElements[i] as HTMLElement).innerText.indexOf(">");
		    if(barIndex < 0) continue;
		    alias = (linkElements[i] as HTMLElement).innerText.substr(barIndex+2);
		    (linkElements[i] as HTMLElement).innerText = alias;
	    }

    }
	
	this.registerMarkdownPostProcessor(postProc);
}
1 Like

This is something I’ve been looking for! Can you help me out on how to use this workaround?

Sorry for the late reply. All you need to do is follow this guide. Then in the file main.ts, replace everything in onload() with the snippet above. Maybe someone will make it a plugin in soon

1 Like

Thanks! I’ve made it into a plugin, it just needs to be added to the community plugins list. In the mean time you can download it here.