Skip to content

christiannaths/jquery.githubcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jQuery.GithubCode

Show your code from any Github repo file or diff by simply dropping in an (almost) ordinary <code> tag into your HTML.

Check out the demo

Note: This is a very early release (probably too early), and there are a few known bugs I'm currently working on. Feel free to file an issue for any bugs you find or feature requests you might have.

Install

dependencies:

Include jquery & jquery.githubcode at the bottom of your page

<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery.githubcode.js"></script>

Usage

Add a <code> tag to your markup, add Github URL via data-url attribute.

<code class="githubcode" data-url="https://github.com/christiannaths/jquery.githubcode/blob/master/src/jquery.githubcode.js"</code>

Fire the plugin on all classes of <code class="githubcode"></code>

$('code.githubcode').githubcode();

Fire the plugin when the DOM is ready

<script type="text/javascript">
  $('code.githubcode').githubcode();
</script>

Example

You probably want to do some sytnax highlighting. (This example uses Prism)

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>GithubCode Example</title>
  <link rel="stylesheet" type="text/css" href="./stylesheets/prism.css" />
</head>
<body>

  <h1>Get A Single File via GH Raw URL</h1>
  <code class="githubcode" data-url="https://github.com/christiannaths/jquery.githubcode/blob/master/src/jquery.githubcode.js"</code>

  <script src="./javascripts/jquery.min.js"></script>
  <script src="./javascripts/prism.js"></script>
  <script src="./javascripts/jquery.githubcode.min.js"></script>
  <script type="text/javascript">
    $('.githubcode').githubcode({
      afterInsert: function($element){
        Prism.highlightAll();
      }
    });
  </script>
</body>
</html>

About

Turn code tags into code snippets from any Github repo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •