mii-key / obsidian-links

manipulate & manage obisidian links
MIT License
106 stars 6 forks source link

Request and suggestion: Automatically get the text of links, without encoding the link #40

Open at2008 opened 3 weeks ago

at2008 commented 3 weeks ago

Automatically get the text of links, without encoding the link.

It is hoped that the code inside function convertLinkToMarkdownLink and convertLinkToMarkdownLink1 can be modified to something like the following:

get text

    if (linkData.type === 2 /* Wiki */ && !text) {
      text = destination; */
    }

Replace with

    if (linkData.type === 2 /* Wiki */ && !text) {
      let pos = destination.lastIndexOf('/');
      if (pos != -1) {
        text = destination.substr(pos+1);
      } else {
        text = destination;
      }
    }

Don't encode the link

      destination = encodeURI(destination);
      if (destination && linkData.type === 2 && destination.indexOf("%20") > 0) {
        destination = `<${destination.replace(/%20/g, " ")}>`;
      }

Replace with

      if (destination && linkData.type === 2) {
        destination = `<${destination}>`;
      }
mii-key commented 2 weeks ago

Hi,

I’d appreciate some clarification on your request:

“Get text” Would you like the note file name to be used as the link text after conversion?

“Don’t encode the link” Could you please provide examples of the problems you encounter with destination encoding?

Thank you!

at2008 commented 2 weeks ago

Thanks for your reply. This plugin is very useful to me, thanks to the author!

“Get text”

Yes, use the name of the note file as the link text, because sometimes the link path is very long and difficult to read.

“Don’t encode the link”

Regarding this, if the link contains Chinese, it becomes unreadable after encoding; [text](<link>) This is the standard supported by the markdown specification, which is more applicable and is supported by obsidian and other marddown tools.