4

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.

Felix Dietrich
  • 127
  • 1
  • 11

1 Answers1

1

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!

Gabe Rogan
  • 3,343
  • 1
  • 16
  • 22
  • 1
    Thank you! I tried this (using GitBook Editor on a Mac), but nothing appears. In the console it says: "Error: HTML and templating tags are not yet supported in document mode." I guess I'll simply have to wait until this is fully developed. I also experimented with JavaScript plug-ins (such as menus etc.) but most of them do not work consistently over Safari, Firefox, Chrome etc. – Felix Dietrich May 11 '17 at 10:05