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

Feature request: Add plain URLs to targets #6

Closed
tadashi-aikawa opened this issue Jan 26, 2021 · 3 comments
Closed

Feature request: Add plain URLs to targets #6

tadashi-aikawa opened this issue Jan 26, 2021 · 3 comments

Comments

@tadashi-aikawa
Copy link
Contributor

Hi. Thank you for an amazing plugin😄

I thought it seems to be handy that not only jump to internal/external links, but also plain URLs.
So I tried to implement it as follows.

2021-01-27_01h14_18

    getSourceLinkHints = (cmEditor: Editor): SourceLinkHint[] => {
        // expecting either [[Link]] or [[Link|Title]]
        const regExInternal = /\[\[(.+?)(\|.+?)?\]\]/g;
        // expecting [Title](link)
        const regExExternal = /\[.+?\]\((.+?)\)/g;
+       // expecting http://hogehoge or https://hogehoge
+       const regExUrl = /(?<= |\n|^)(https?:\/\/[^ \n]+)/g;

	const strs = cmEditor.getValue();

	let linksWithIndex: { index: number, type: 'internal' | 'external', linkText: string }[] = [];
	let regExResult;

	while(regExResult = regExInternal.exec(strs)) {
		const linkText = regExResult[1];
		linksWithIndex.push({ index: regExResult.index, type: 'internal', linkText });
	}
		
	while(regExResult = regExExternal.exec(strs)) {
		const linkText = regExResult[1];
		linksWithIndex.push({ index: regExResult.index, type: 'external', linkText })
	}
        
+       while(regExResult = regExUrl.exec(strs)) {
+       	const linkText = regExResult[1];
+       	linksWithIndex.push({ index: regExResult.index, type: 'external', linkText })
+       }

What do you think?

@mrjackphil
Copy link
Owner

@tadashi-aikawa Hey, feel free to create a pull request.
I'll check and merge it if it works fine!

Thanks for your effort. You are awesome!

tadashi-aikawa added a commit to tadashi-aikawa/obsidian-jump-to-link that referenced this issue Jan 30, 2021
@tadashi-aikawa
Copy link
Contributor Author

I have created PR 😉

mrjackphil added a commit that referenced this issue Feb 7, 2021
@mrjackphil
Copy link
Owner

@tadashi-aikawa sorry for the delay. Feature approved :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants