zhaoshenzhai/obsidian-mathlinks

[Bug] Internal links with extensions are not rendered correctly

RyotaUshio opened this issue · 1 comments

This seems to be a minor issue since most users would prefer links without extensions, but mathLink is not correctly rendered in reading view when a link path has an extension.

I've noticed the problem is that the condition checks in setMathLinkGetter is not going as expected.

setMathLinkGetter(): () => string {
let getter = () => "";
if (this.displayText != this.targetLink && this.displayText != translateLink(this.targetLink)) {
// [[note|display]] -> use display as mathLink
getter = () => this.displayText;
} else {
const targetName = this.targetFile?.basename;
if (this.displayText == targetName || this.displayText == translateLink(this.targetLink)) {
// [[note]], [[note#heading]] or [[note#^blockID]]
getter = () => getMathLink(this.plugin, this.targetLink, this.sourcePath);
}
}
return getter;
}

Probably the following lines have something to do with it. To be honest, I don't fully understand the intention behind them...

Here's some test I've done with v0.4.4 (32356cd):

When both mathLink & mathLink-blocks are set

Live preview

image

Reading view

image

When mathLink is absent

Live preview

image

Reading view

image

Hi, thanks for pointing it out!

Probably the following lines have something to do with it. To be honest, I don't fully understand the intention behind them...

The replace(/\.md/, "") was added to render links like [Main](Main.md) with Main.md having mathLink: $\alpha$ as $\alpha$ (in MathJax). Without it, it would render as Main.

const targetName = this.targetFile?.basename;

I'm not sure why I specifically picked out the basename either...

I will address your solution in the PR.