Creating an Angular Highlight Directive

Ole Ersoy
1 min readNov 28, 2018

--

Photo by Mahesh Ranaweera on Unsplash

Scenario

We have the following typescript code block to render with highlight.js :

<pre><code highlight class="typescript">
private fileReader:FileReader = new FileReader();
</code></pre>

Note the declaration of the highlight directive.

Solution

Create the following directive. Note that the Stackblitz editor contains a complete example:

If you select the text private fileReader:FileReader = new FileReader() with Chrome dev tools, you will see that it has been highlighted.

--

--

Ole Ersoy
Ole Ersoy

Written by Ole Ersoy

Founder of Firefly Semantics Corporation

No responses yet