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 usemarkText
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.
Would it be possible to use an anchor tag, for better accessibility?
Not in CodeMirror 5.x, but version 6 allows you to wrap decorated text in arbitrary inline tags.
Wait seriously, how?
See the tagName
option to Decoration.mark
.