Code Snippets from GitHub Gists

Code Snippets from GitHub Gists

A Confluence app. Not made or endorsed by GitHub.

Embed public GitHub gists in Confluence pages with syntax highlighting. Show one file or every file as tabs, show only a range of lines, and highlight the lines that matter.

A Forge app with a UI Kit macro. It reads gists from GitHub's public REST API (api.github.com). That is its only external connection, and it is declared in the manifest.

Features

Paste any gist link

The macro takes these forms.

Links to a gist's revisions, forks or stargazers page are refused, with a message that says so.

Pick a file, a range and the lines to highlight

Leave File empty to show every file as tabs (up to 20). Or name one file. Names match exactly first, then without regard to case. A link with a #file-… anchor or ?file= picks that file by itself.

Lines takes 10-25, 12, or 40- (from line 40 to the end). A link copied with GitHub's line anchor (#file-app-js-L10-L25) sets the range by itself, also when File names the same file. The Lines setting wins over the anchor. If File names a different file, the anchor's lines aren't used.

Highlight lines takes 12, 15-17. These are the file's own line numbers, as GitHub shows them, even when only a range is shown. Line numbers past the end of the file are left out, and a note says so.

Highlighting and display

Syntax highlighting covers about 70 languages (74 CodeBlock language values, counting aliases such as bash/zsh and plain text). The language comes from GitHub's own detection, with the file extension as a fallback. Unknown languages show as plain text.

Line numbers can be on or off. Long lines scroll sideways or wrap. A pinned revision shows a "revision abc1234" label and never changes.

Fast and gentle on GitHub's limits

A GitHub token is optional, but we recommend one

Confluence admins can add it under Settings → Code Snippets from GitHub Gists. It raises GitHub's limit from 60 to 5,000 requests an hour. Without a token, requests come from Forge's cloud addresses, which may be shared with other apps. GitHub counts its 60 anonymous requests an hour per address, so that limit may already be used up. We haven't measured this yet.

The token is checked with GitHub before it's saved, kept in Forge secret storage, sent only to api.github.com, and never shown again. If it later expires or is revoked, gists keep loading anonymously. The token is tried again after an hour, and the settings page shows a warning until an admin replaces or removes it.

Using the macro

  1. In the editor, type /Code snippet from GitHub Gist and insert the macro.
  2. Open its settings and paste the gist URL or ID. Optionally fill in File, Lines and Highlight lines, and choose Line numbers and Long lines.
  3. Publish. Readers see the code with a link to the gist on GitHub.

These are the messages you may see.

MessageMeaning
Check the macro settingsThe link, file name, range or highlight could not be read. The message says why.
File not found in this gistLists the gist's files, so you can copy the right name.
Lines out of rangeThe range starts after the last line of the file.
Gist not foundGitHub has no such gist. It was deleted, or the ID is wrong. A revision link with a SHA that GitHub doesn't know shows this too, and names the revision. The app remembers a missing gist for 5 minutes and an unknown revision for 1 hour.
GitHub limit reachedGitHub's hourly limit (or its short-term "secondary" limit) is used up, and there is no saved copy. It gives the reset time. An admin can add a token.
Showing a copy saved … agoGitHub could not be asked just now, so the last saved copy is shown.

When File is empty, Lines and Highlight are ignored, and a note says so. A range only makes sense for one file.

Limits

What gets shown has a few more rules.

Data and privacy

The gist ID, and the revision when one is pinned, go to api.github.com. So does the admin's token, if one is set. Nothing from your Confluence pages or users is sent.

The app stores public gist data only. That means the owner's login, the description, file names, languages and contents. It's kept in Forge storage for up to 24 hours (48 hours for pinned revisions), plus the optional token. No avatars or other profile data are stored.

Because it contacts GitHub, the app doesn't qualify for the Runs on Atlassian badge. See PRIVACY.md.

Support Zovo

Zovo builds and maintains this app. If it saves you time, you can support the work on GitHub Sponsors. Sponsorship is optional, and the tool works the same without it.

Zovo is made by theluckystrike on GitHub.

More tools by Zovo

License

MIT. See LICENSE. GitHub and Gist are trademarks of GitHub, Inc. They are used here only to say which service the app works with. This app is not made or endorsed by GitHub.

Support this work

If this app saves you time, you can support the work on GitHub Sponsors. Monthly tiers start at $5, and one-time tiers start at $15. Sponsorship is optional, and the tool works the same without it.

Sponsor on GitHubZovo on GitHub