I am currently working on implementing syntax highlighting for all code elements within dynamically added HTML content that will be appended to the existing page using ng-bind-html.
<div ng-repeat="activity in activities">
<h3>{{activity.title}}</h3>
<div ng-bind-html="activity.text">
</div>
</div>
The activity.text
variable typically contains content like this:
<p>This is a paragraph with some code following.</p>
<pre><code class="lang-python">
s = "Python syntax highlighting"
print s
</code></pre>
<p>some other HTML elements </p>
Currently, the setup is functional but lacking syntax highlighting. To address this issue, I have implemented highlightjs and angular-highlightjs. The modification made was changing
<div ng-bind-html="activity.text">
to <div hljs ng-bind-html="activity.text">
.
However, there is a challenge encountered with how ng-bind-html and hljs directives interact; the expected syntax highlighting is not applied specifically to code tags (pre code), but rather to the entire HTML content.
Seeking advice on alternative approaches to achieve syntax highlighting for dynamically loaded content.