How to create custom clickable sequence of characters

60 Views Asked by At

I would like to customize an existing highlightjs language definition,
so some character sequences (based on a regex) become clickable.

The usage scenario is code example in a documentation, where some expressions can be links leading to another documentation page.

Reading the documentation, I understand that I should extend existing language definition in order to add a custom scope, or perhaps Markups, but don't know how.

(Disclaimer: Never played with JavaScript before)

Minimalistic example:

Code

static_assert(csl::ag::size<A>::value == 2);
//            ^^^^^^^^^^^^^^^^ goal : this expression as a link

Current behavior :

<code class="hljs language-cpp">

<span class="hljs-built_in">static_assert</span>
(csl::ag::size&lt;A&gt;::value == 
<span class="hljs-number">2</span>);

</code>

Expected behavior:

<code class="hljs language-cpp">

<span class="hljs-built_in">static_assert</span>
(
<span class="hljs-some_custom_name_here">csl::ag::size&lt;A&gt;</span>
::value == 
<span class="hljs-number">2</span>);

</code>

Where <span class="hljs-some_custom_name_here">csl::ag::size&lt;A&gt;</span> will then become clickable with extra code.

0

There are 0 best solutions below