Detect URLs

I’m very happy with CM6. Impressive work!

I like to use it a simple Markdown editor with some extra features. Already installed lang-markdown.

No I’d like to add the class cmt-url to all URLs in the document. Not just the URLs in Markdown link elements. Is there a way to do this? Do I need an extra language or grammar for that? Does such a thing exist?

Thanks for your help
Roberto

You’ll need a Markdown parser extension to make it assign a token type to URLs in text, then you have to assign a highlight tag to that token in your CodeMirror 6 language, and make sure your highlight style marks such tags with class cmt-url.

Thanks for your quick answer! What do you mean by Markdown parser extension? I am already using lang-markdown, but the global highlighting of URLs is independent of the Markdown highlighting.

If you don’t care about language-awareness (and also want them highlighting inside, say, code blocks or link titles) you could also use MatchDecorator.

1 Like

Awesome! Exactly what I was looking for. Thanks a lot. Will try to implement a view plugin now.