Starting with Cesium 1.21 on May 2, Sandcastle now integrates with the GitHub API for importing and exporting code examples.

There are two new buttons in the Sandcastle toolbar: Share and Import Gist.

To share code you’ve written in Sandcastle, just click the Share button and copy the link. When you click Share, the code is POSTed to an anonymous GitHub Gist.

When someone visits the link, Sandcastle loads and runs the code example, for example, visit:

http://cesium-dev.s3-website-us-east-1.amazonaws.com/cesium/master/Apps/Sandcastle/?src=Hello%20World.html&label=Showcases&gist=20d3badfddb319a17d29953a50cdb0c5

You’ll notice the query parameter gist, which is the ID to the actual GitHub Gist that is loaded into Sandcastle.

Existing Gists, like https://gist.github.com/TomPed/f028e4d7b79711a325ef077c53307472, can also be imported into Sandcastle. Just paste in the whole link of the Gist or just the Gist’s ID (like in the screenshot below) to import.

Be sure to use this feature for including a code example when submitting an issue to the Cesium GitHub repo.

If you can’t wait for Cesium 1.21, check this out right now using the hosted version of Sandcastle from the master branch on GitHub thanks to Cesium’s new Continuous Integration.