githubgist

Can I embed source files from GitHub on my web page other than Gists?


Context

You can create a Gist on GitHub and embed it on your web page: embedding Gists.

This is an example of a randomly chosen Gist: tap.groovy.

Question

Is embedding also possible with other code files from GitHub, for example with this randomly chosen C# file ICommand.cs which is not a Gist?


Solution

  • One could just fetch the file to embed on one's website.

    fetch("https://raw.githubusercontent.com/Ayanmullick/test/master/AutomationAcc/test1.ps1")
          .then(response => response.text())
          .then(data => document.getElementById('code').textContent = data)
    <pre id="code"></pre>