obsidian-url-into-selection icon indicating copy to clipboard operation
obsidian-url-into-selection copied to clipboard

decode uri: for better readability

Open Benature opened this issue 3 years ago • 4 comments

decode url like Chinese or other special characters for better readability

Benature avatar Aug 15 '21 04:08 Benature

I applied the diff to my local vault and it works, thanks! However it has a problem. If the decoded URL has a space in it, the link becomes invalid in Markdown and gets resolved incorrectly by Obsidian. In that case, surrounding the link with angled brackets solves it, like so: [link text](<https://example.org/some made up URL with spaces>).

NomarCub avatar Jan 18 '23 21:01 NomarCub

Indeed, sorry that I overlook this condition. I add a replace so that space will keep in %20, I think this can solve the problem.

Benature avatar Jan 19 '23 04:01 Benature

There are whitespace characters other than the normal space that break this, such as the full-width space ( ) used in Japanese. It would probably be a more universal and safe solution to detect if the string has any whitespace, and if it does, wrap it in brackets.

NomarCub avatar Jan 19 '23 12:01 NomarCub

Oh! I miss reading the <> in your first comment🤦‍♂️

I use /\s/g to detect space, and check whether the URL is wrapped in brackets already (/^<.*?>$/g), as processUrl() may add brackets.

Benature avatar Jan 20 '23 10:01 Benature