Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include code from GitHub as code block in GitBook

How can I display raw code like this in GitBook?

https://raw.githubusercontent.com/luyongxu/SignalPlot/master/Code/1.016%20Asset%20Bubbles.R

I believe this is related to: Reading code from GitHub as text (raw) in a web page But I don't know how to call the JavaScript function in the main document.

like image 218
Felix Dietrich Avatar asked Apr 26 '26 23:04

Felix Dietrich


1 Answers

Just add a book.json file to your GitBook. Paste this into it:

{
    "plugins": ["github-embed"]
}

Now just put something like this in your page:

{% github_embed "https://github.com/v5analytics/gitbook-plugin-github-embed/blob/1cd16ac/index.js#L3-L8" %}{% endgithub_embed %}

It's that simple!

Here's some documentation.

Note: I've got it working locally (using gitbook install and gitbook serve), but it's not working for me on GitBooks, so I've filed an issue here and here.

(proof it's working locally) enter image description here

Apologies on behalf of gitbook-plugin-github-embed for their deprecated code!

like image 79
Gabe Rogan Avatar answered Apr 29 '26 12:04

Gabe Rogan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!