hyperlinking a text in codemirror


I want a part of code in codemirror to be turned into hyperlink on alt-mouseover. Can someone suggest a good way to do it ?


You can’t turn the content DOM itself into a hyperlink, but you can do something like this:

  • Register a mouseover handler on the editor

  • When the mouse goes over a token that you are interested in (say, a span with cm-link class, or you could use markText to add a specific class to the elements you’re interested in)…

  • Use charCoords to find the position of that token and overlay your own link, styled to look like the content, over the editor.


You can also try to use markText to replace the text with an atomic element that you watch for mouseovers on. You won’t really be able to edit it as easily, though.