Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support file URLs and non-http URIs #3

Closed
Cito opened this issue Nov 19, 2020 · 14 comments
Closed

Support file URLs and non-http URIs #3

Cito opened this issue Nov 19, 2020 · 14 comments

Comments

@Cito
Copy link
Contributor

@Cito Cito commented Nov 19, 2020

As far as I see, this plugin checks if the clipboard contains a valid http/https URL and does not paste otherwise.

  • It would be nice if the plugin would also check if this is a valid file path (either POSIX or Windows) and then paste it as a link with the file URI scheme. This way you can create links to other documents or directories on your local filesystem.

  • It should also url encode blanks to %20 (maybe also other special characters), and in case of a Windows path, it should also convert backslashes to forward slashes.

  • There should be an option to use the angle bracket notation of CommonMark for links that contain spaces, instead of url encoding them. This makes the link better readable.

  • Also, if the clipboard content is neither a valid URL nor file path, maybe it should show an error message explaining what is wrong instead of simply doing nothing.

  • Maybe, if the clipboard content is a valid URI with a different scheme than http: or https: (like ftp: or mailto:) it should also be pasted. Registered and unregistered schemes (e.g. for opening certain apps) should be recognized.

@DandyLyons
Copy link

@DandyLyons DandyLyons commented Dec 16, 2020

It doesn't work for me even if it's a https URL.

@Cito
Copy link
Contributor Author

@Cito Cito commented Dec 16, 2020

@DandyLyons This must be different problem, as https URLs like the one for this issue definitly work for me. Make sure the plugin is enabled and you're in edit mode when pasting.

@MSzturc
Copy link

@MSzturc MSzturc commented Jan 26, 2021

+1

Would love to use this with denonthink links. (x-devonthink-item://C6FEBBD8-109A-4309-B227)

@Benature
Copy link

@Benature Benature commented Feb 4, 2021

+1

Would love to use this with marginnote links. (eg: marginnote3app://note/FC25E951-1CFF-431E-899B-2724A7E8432A)

@Benature
Copy link

@Benature Benature commented Feb 4, 2021

Just as a walkaround, I modified the regex string in main.js to satisfy the URL scheme format, which is much less strict

UrlIntoSelection.prototype.isUrl = function (text) {
    var urlRegex = new RegExp(
      "^[a-z0-9-]+:\\/\\/[a-zA-Z0-9-]+"
    );
    return urlRegex.test(text);
  };

Now I can paste marginnote links and devonthink links

@NeighNeighNeigh
Copy link

@NeighNeighNeigh NeighNeighNeigh commented Feb 16, 2021

Hey @Benature

This fix doesn't seem to work for file:/// URI's. (I imagine because of the 3 required slashes?)
Any way to have the regex include these as well?

Thanks ♡

@Cito
Copy link
Contributor Author

@Cito Cito commented Feb 16, 2021

@NeighNeighNeigh Yes, the urlRegex above does not allow for three slashes. An URL like file:/path URLs which is also valid does not pass either - see file URI scheme for what is allowed here.

@NeighNeighNeigh
Copy link

@NeighNeighNeigh NeighNeighNeigh commented Feb 16, 2021

@Benature
Copy link

@Benature Benature commented Feb 16, 2021

@NeighNeighNeigh hello, maybe you can try

UrlIntoSelection.prototype.isUrl = function (text) {
    var urlRegex = new RegExp(
      "^[a-z0-9-]+:(\\/){2,3}[a-zA-Z0-9-]+"
    );
    return urlRegex.test(text);
  };

it allows two or three slashes.

@NeighNeighNeigh
Copy link

@NeighNeighNeigh NeighNeighNeigh commented Feb 16, 2021

@Benature thank you for taking the time to refine this further, I really appreciate it. Now working great over here 😃

@denolehov
Copy link
Owner

@denolehov denolehov commented Mar 29, 2021

I've tested the solution provided by @Benature and it didn't work 😕

But I've exposed URL regex as a plugin setting in v1.2.0. You can find in Settings > Plugin Options > Paste URL into selection and specify regular expression tailored to your needs 🙂

@NeighNeighNeigh
Copy link

@NeighNeighNeigh NeighNeighNeigh commented Mar 30, 2021

Hi @denolehov. I was having great success using @Benature's modification- But now with the new update, if I use Benature's regex it fails. It would be nice to have the option to just forego the regex check completely– as I know I have a url in my clipboard and when I use my custom shortcut it should paste whatever is in my clipboard as URL.

@denolehov
Copy link
Owner

@denolehov denolehov commented Apr 19, 2021

@NeighNeighNeigh Please try this regex: ^[a-z0-9-]+:(\/){2,3}[a-zA-Z0-9-]+ (notice that / is escaped once).

@NeighNeighNeigh
Copy link

@NeighNeighNeigh NeighNeighNeigh commented Apr 19, 2021

Yep working here now, thank you :)

aidenlx added a commit to aidenlx/obsidian-url-into-selection that referenced this issue Apr 21, 2021
aidenlx added a commit to aidenlx/obsidian-url-into-selection that referenced this issue Apr 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants