I have code like this:
var ref = 'http://www.example.com/test.html';
var ref2 = 'http://www.example.com/test2.html';
Not really easy, but what you'd do is:
Write an overlay mode that recognizes such links. Basically, this is a mode that spits out a custom token type when it finds something that looks like a link, and null otherwise. You can use the simple mode addon to make this easier. You can use this token type's CSS class (for example
cm-link) to style your links.
Make your editor use your overlay by calling the
mousedown event handler on your editor (
In this handler, check whether the event's
target has the link CSS class. If it does, the user is clicking a link.
If so, use the
coordsChar method, using the coordinates from your mouse event, to find the position in the document that was clicked. Extract the actual link from the document text around that position, and follow it.
(Or, even better, instead of directly interfering with the click, which might be intended to put the cursor in the link or select it, show a widget containing a regular link whenever the cursor is inside of link text.)