Coder Social home page Coder Social logo

theorix / gitbook-plugin-github-embed Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hamishwillee/gitbook-plugin-github-embed

0.0 0.0 0.0 178 KB

Embed code from Github repos into a GitBook

License: Apache License 2.0

JavaScript 99.06% CSS 0.94%

gitbook-plugin-github-embed's Introduction

npm version Build Status

Embed Github Snippets into Gitbooks

Embed snippet text or whole files from Github repos into a GitBook.

{% github_embed "[github url]", [options] %}{% endgithub_embed %}

Where [github url] is:

https://github.com/[owner]/[repo]/blob/[ref]/[path]#[line numbers]

Will produce something like this given the URL: https://github.com/v5analytics/gitbook-plugin-github-embed/blob/1cd16ac/index.js#L3-L8

website: {
    assets: "./book",
    css: [
        "github-embed.css"
    ]
},

index.js (lines 3โ€“8)

Examples

// Load latest version of file "tag.js"   
{% github_embed "https://github.com/v5analytics/gitbook-plugin-github-embed/blob/master/src/tag.js" %}{% endgithub_embed %}

// Load latest version of file "tag.js" and show line 3
{% github_embed "https://github.com/v5analytics/gitbook-plugin-github-embed/blob/master/src/tag.js#L3" %}{% endgithub_embed %}

// Load latest version of file "tag.js" and show lines 1-5   
{% github_embed "https://github.com/v5analytics/gitbook-plugin-github-embed/blob/master/src/tag.js#L1-L5" %}{% endgithub_embed %}

// Load specific version of file "tag.js" and show lines 1-5   
// Press "Y" key in github to switch from master/latest to last commit
{% github_embed "https://github.com/v5analytics/gitbook-plugin-github-embed/blob/9ef6e532/src/tag.js#L1-L5" %}{% endgithub_embed %}

// Load full file, but hide interior lines
{% github_embed "https://github.com/v5analytics/gitbook-plugin-github-embed/blob/9ef6e532/src/tag.js", hideLines=['15-87'] %}{% endgithub_embed %}

Options

  • showLink=true Show a link below the embedded source back to the source file. Defaults to true

      {% github_embed "[url]", showLink=false %}{% endgithub_embed %}
    
  • reindent=true Re-indent the lines given the line numbers. Defaults to true

      {% github_embed "[url]", reindent=false, showLink=false %}{% endgithub_embed %}
    
  • hideLines=[] Hide interior lines in a snippet. Should be in ascending order, can contain a range as a string.

      {% github_embed "[url]", hideLines=[2, '4', '7-10'] %}{% endgithub_embed %}
    

Styling the Link

Use a gitbook style override to adjust the style of the link. The class is .github-embed-caption.

Avoiding Rate Limit Errors

Set an environment variable to avoid rate limits. Create Token

GITBOOK_EMBED_GITHUB_API_TOKEN=[API Token]
# or
GITBOOK_API_TOKEN=[API Token]

gitbook-plugin-github-embed's People

Contributors

jharwig avatar hamishwillee 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.