zhaoshenzhai / obsidian-mathlinks

An Obsidian.md plugin to render MathJax in your links.
MIT License
61 stars 4 forks source link

Markdown links for headings/blocks have problem #47

Open RyotaUshio opened 1 year ago

RyotaUshio commented 1 year ago

As shown in the image below (this is the sandbox vault), MathLinks has some issues when dealing with a markdown link []() for a heading or a block. Note that the markdown links are inserted by the built-in suggestion (the one triggered when typing [[) after turning OFF Use [[WIkilinks]].

Heading

In live preview, the MD link to the heading is not properly rendered because Obsidian replaces \ with whitespace.

Block

  1. By default, the display text is empty for block reference, like [](#^92f67b). So mathLink is not rendered.
  2. A possible solution to this problem would be setting #^blockID as the display text, i.e. [#^92f67b](#^92f67b). But this works only in live preview.

<- Live preview | Reading view ->

image

source:

---
mathLink: $\mathcal{N}$ote!
mathLink-blocks:
  "92f67b": $\mathbb{BLOCK}$
---

# $\hbar$eading

> block

^92f67b

# Wikilinks work perfectly

- `[[MathLinks test]]`: [[MathLinks test]]
- `[[#$ hbar$eading]]`: [[#$ hbar$eading]]
- `[[#^92f67b]]`:  [[#^92f67b]]

# Markdown link doesn't for headings/blocks

- `[MathLinks test](MathLinks%20test.md)`: [MathLinks test](MathLinks%20test.md)
- `[$ hbar$eading](#$%20hbar$eading)`: [$ hbar$eading](#$%20hbar$eading)
    - Probably this happens because Obsidian replaces the backslash `\` with whitespace.
    - It works after manually fixing this: `[$\hbar$eading](#$%20hbar$eading)`: [$\hbar$eading](#$%20hbar$eading)
- `[](#^92f67b)`: [](#^92f67b)
- Workaround? `[#^92f67b](#^92f67b)`: [#^92f67b](#^92f67b)
    - This works in live preview, but not in reading view
    - Essentially the same applies to the wikilink counterpart `[[#^92f67b|#^92f67b]]`: [[#^92f67b|#^92f67b]]

debug info:

SYSTEM INFO:
    Obsidian version: v1.4.11
    Installer version: v1.3.5
    Operating system: Darwin Kernel Version 22.3.0: Thu Jan  5 20:53:49 PST 2023; root:xnu-8792.81.2~2/RELEASE_X86_64 22.3.0
    Login status: not logged in
    Insider build toggle: off
    Live preview: on
    Legacy editor: off
    Base theme: dark
    Community theme: none
    Snippets enabled: 0
    Restricted mode: off
    Plugins installed: 1
    Plugins enabled: 1
        1: MathLinks v0.4.5

RECOMMENDATIONS:
    Community plugins: for bugs, please first try updating all your plugins to latest. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community plugins.
RyotaUshio commented 1 year ago

To be honest, I'm not sure to what extent we should support markdown links.

I don't see any point in using markdown links in Obsidian (except for external links) in my opinion. They always force us to set the displayed text manually, and the displayed text is hard to auto-update when the note title changes. If we need markdown links for compatibility with other applications, we can simply convert wikilinks into markdown links.

It might be an option to focus on wikilinks and admit some features don't perfectly work for markdown links.