Code Monkey home page Code Monkey logo

gist-embed's Introduction

##How to use gist-embed to spice up code snippets on your blog

Include jQuery and gist-embed:

You should include them in your HEAD tag for better performance

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://github.com/kashif-umair/gist-embed/raw/master/gist-embed.js"></script>

Add a code element to your page with an id attribute in the following format:

"gist-<gist-id>"

To embed the whole gist you should put this code element in your body where ever you want it to be displayed.

<code id="gist-4672365"></code>

To embed a single file from gist, add the data-file attribute to your code element like this.

<code id="gist-4672365" data-file="2.java"></code>

To embed a single line of a file from gist, add the data-line attribute to your code element like this.

<code id="gist-4672365" data-file="2.java" data-line="5"></code>

This will embed only line number 5.

To embed multiple lines of a file from gist, change the data-line attribute's value to something like MS Word printing page ranges. e.g.

<code id="gist-4672365" data-file="2.java" data-line="2-5,10-14,11,20"></code>

This will embed line numbers 2,3,4,5,10,11,12,13,14,11,20 in the same order. If lines are duplicated then they will be duplicated in code too.

If you are embedding multiple lines then make sure about following points.

  • You can put a range like "2-5", or single line numbers separated with commas like "11,20", or mix of both like "2-5,11,10-14,20"
  • Spaces are not allowed in data-line value

To avoid line numbers in view, you can use data-showLineNumbers attribute. To hide line numbers set this attribute to "false"

<code id="gist-4672365" data-file="2.java" data-line="2-5,10-14,11,20" data-showLineNumbers="false"></code>

 This code will hide the line numbers at left side of your code.

To hide footer content of gitHub in view, you can use data-showFooter attribute. Simply set this attribute's value "false".

<code id="gist-4672365" data-file="2.java" data-line="2-5,10-14,11,20" data-showFooter="false" ></code>    

 This will hide footer github contents (gistName hosted with by GitHub).

Follow the above instructions to avoid getting any undesired results.

gist-embed's People

Contributors

kashif-umair avatar jayaramki avatar adoo avatar khoinguyen avatar ezoomagency avatar

Stargazers

Altela Eleviansyah Pramardhika avatar Aston Li avatar Jaume Bonet avatar Jacob Lett avatar Jason Barnidge avatar Chunliang Lyu avatar  avatar Yusuke Kuoka avatar Lu Nelson avatar Vinny Pasceri avatar Matija Grcic avatar anam.mansoor avatar Inno avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.