jensmtg / influx

An alternative backlinks plugin, which displays relevant and formatted excerpts from notes with linked mentions, based on the position of mentions in the notes' hierarchical structure (bullet level indentation).
MIT License
310 stars 14 forks source link

Influx previews are incorrect when backlinks use Markdown Links (with possible solution) #50

Closed kenlim closed 1 year ago

kenlim commented 1 year ago

Describe the bug When a document uses Markdown Links instead of the default "Shortest path when Possible" WikiLinks, Influx does not render the preview correctly.

To Reproduce Steps to reproduce the behavior:

  1. Create a target note called "target"
  2. Create a referring note called "markdown referral"
  3. In the note "markdown referral", add the following block of text:
# This is the top heading
This is the first paragraph

# This uses Markdown Links
[Target](./target.md) This will not appear in the Influx preview
  1. Return to "target.md", and observe the Influx widget.
  2. Notice that it links to the correct "markdown link" note, but only displays "This is the top heading"

Expected behavior The Influx widget should link to the correct "markdown link" note, and displays:

# This uses Markdown Links
[Target](./target.md) This will not appear in the Influx preview

Screenshots image

Desktop (please complete the following information):

kenlim commented 1 year ago

Hey there, I think there is a solution to this. The compareLinkName method in the apiAdapter.tsx file doesn't return true when the link is a Markdown link.

with some additional code, you can make it work with Markdown links.

Very quickly, here it is:

compareLinkName(link: LinkCache, basename: string) {

    // format link name to be comparable with base names:

    const path = link.link;
    // grab only the filename from a multi-folder path
    const filenameOnly = path.split("/").slice(-1)[0]

    // strip any block references from the end and the ".md" extension
    const linkname = filenameOnly.split("#^")[0].split(".md")[0]

    if (linkname.toLowerCase() === basename.toLowerCase()) {
        return true
    }
    return false
    }

markdown links that used to fail and will now work:

With this, it works for me on my install:

image

kenlim commented 1 year ago

Have raised pull request (https://github.com/jensmtg/influx/pull/51).

jensmtg commented 1 year ago

Implemented. Thanks!