GitXplorerGitXplorer
h

gitbook-plugin-github-embed

public
0 stars
5 forks
0 issues

Commits

List of commits on branch master.
Unverified
f55c4cb6853a08623d2489ea2eb1ac1dea8c890e

Remove const - not supported by node4

hhamishwillee committed 7 years ago
Unverified
1ac39bd757fb721be431da3dea10fa525756ae9c

Add logging

hhamishwillee committed 7 years ago
Unverified
99ef2bfd29be6c73a99cd70c13e3f2a83a502d0b

Bump version

jjharwig committed 8 years ago
Unverified
b484f188c861e104e8fdd5ee751238eed2bb7fea

Don't swallow errors

jjharwig committed 8 years ago
Unverified
6078b58e88af1f2cc32f729135d811cf56b4b087

install yarn in travis

jjharwig committed 8 years ago
Unverified
076b5bd69da5c8416ec4f2b9bc304564fddfc73a

Add badges

jjharwig committed 8 years ago

README

The README file for this repository.

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]