I cannot get syntax highlighting to work for code fetched from GitHub.
fetch("https://raw.githubusercontent.com/Ayanmullick/test/master/AutomationAcc/test1.ps1")
.then(response => response.text())
.then(data => document.getElementById('code').textContent = data)
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/atom-one-dark-reasonable.min.css">
<script src="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/languages/powershell.min.js"></script>
<script>hljs.highlightAll();</script>
<pre>
<code class="pwsh" id="code"> </code>
</pre>
However, it's working with code in the same file.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/atom-one-dark-reasonable.min.css">
<script src="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/languages/powershell.min.js"></script>
<script>hljs.highlightAll();</script>
<pre><code class="pwsh">
#PowerShell Hello World
param
(
[Parameter(Mandatory=$false)]
[String] $Name = "World"
)
"Hello $Name!"
</code></pre>
How should one use the code and pre tags together to highlight code fetched from GitHub?
<code><pre>...</pre><'/code>and second has<pre><code>....</code></pre><pre id="code"><code class="pwsh"> </code> </pre>didn't work with the GitHub fetched code either.<code>(not the pre) and make sure thathljs.highlightAll();is called after you loaded the code snippet into<code>hljs.highlightElement()method.