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

Plain text URLs should auto-hyperlink after pasting into editor #393

Closed
cknific opened this issue May 10, 2016 · 1 comment
Closed

Plain text URLs should auto-hyperlink after pasting into editor #393

cknific opened this issue May 10, 2016 · 1 comment

Comments

@cknific
Copy link

cknific commented May 10, 2016

pasting urls

If I hit enter key or spacebar after pasting a plain text URL, I'd expect that it to turn into a hyperlinked URL. Evernote and Word behave like this.

@bantic
Copy link
Collaborator

bantic commented Jun 8, 2016

Thanks for raising this. mobiledoc-kit aims to prescribe as little extra-curricular functionality like this as possible, and instead provide a good SDK that allows editor creators to modify it to suit their needs.

In this case, the onTextInput hook could be used to do this auto-formatting. There's an example in the initial PR (here) that describes how this might look:

let urlRegex = /(https?:\/\/[^ ]+) $/; // match a url-like string AND the space after it
editor.onTextInput({
  match: urlRegex,
  run(editor, matches) {
    let url = matches[1];
    let range = editor.range;
    editor.selectRange(range.move(-1).extend(-1 * url.length)); // select the URL
    editor.run(postEditor => {
      let link = postEditor.builder.createMarkup('a', {href: url});
      postEditor.toggleMarkup(link);
    });

    editor.selectRange(range); // restore original cursor position
  }
});

I'd be happy to take a PR that adds this to the README (perhaps in a FAQ or how-to/cookbook section) so that others can see how it could be done. We're not going to bake this functionality into the editor just yet. In the future I could see it being either a default or a plugin that could be added to mobiledoc-kit, though, for those that expect/need this functionality.

@bantic bantic closed this as completed Jun 8, 2016
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