• Stars
    star
    492
  • Rank 89,083 (Top 2 %)
  • Language
    JavaScript
  • License
    Creative Commons ...
  • Created over 2 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Make expandable explanations!

Nutshell: make expandable explanations

Check out the demo here!

Nutshell uses the open-source libraries DOMPurify & Marked. Other than that, all my original content in this repo โ€“ code, art & words โ€“ are dedicated to the public domain under the Creative Commons Zero waiver.

Readme's Table of Contents:

There will be no Version 2.0.0

โ€œRunning a successful open source project is just Good Will Hunting in reverse, where you start out as a respected genius and end up being a janitor who gets into fights.โ€

~ Byrne Hobart

Nutshell is open-source, but this is not a "I will take requests & maintain this for the rest of my pathetic life" kind of project. I am pre-committing, right here, to keeping Nutshell minimalist, and only making minor tweaks. There will be no Version 2.0.0 of Nutshell.

That said, I'm accepting two kinds of Pull Requests! 1) Bug fixes, and 2) Translations.

Bug fixes are self-explanatory. Translations are slightly harder.

On translating:

(Translations already done: French, Esperanto, Dutch, German, Polish, Spanish, Chinese, Hebrew, Turkish, Korean, Russian, Hindi)

In the nutshell.js file, there's a JSON object containing all of Nutshell's English text:

Nutshell.language = {
	en: {

		// Button text
		closeAllNutshells: `close all nutshells`,

		// Nutshell errors...
		notFoundError: `Uh oh, the page was not found! Double check the link:`,
		wikiError: `Uh oh, Wikipedia's not loading, or the link is broken. Please double check:`,

[and so on...]

To help translate Nutshell:

  1. Copy the "en" object
  2. Add a new object to Nutshell.language with the 2-letter code for your target language
  3. Translate everything (~150 words) in backtick-quotes (but leave alone the stuff inside [square brackets] or <angular brackets>!!!)
  4. Send a Pull Request! ๐ŸŽ‰
  5. Give me two weeks to slog through my Sisyphean inbox & finally merge it.

Note: I'm only accepting translations for the Nutshell library, not the demo website.

I'm also not accepting Pull Requests for new features, but feel free to suggest some in the Issues tab, and emoji-upvote (๐Ÿ‘) others' suggestions! This will not determine what I make, I'm just curious what y'all want. I am pre-committing: I will only implement minor features *I* personally want.

(If there's a feature you want but I don't, make a fork! Then post your fork in the corresponding Issue, so everyone who also wants that feature can use it, too.)

Possible future shtuff

If you're curious, here's some minor features I maybe MAYBE might add:

  • In-built support for:
    • Wiktionary
    • Vimeo
    • LaTeX?? (though, this may be bloat... maybe math blogs oughta install LaTeX-rendering separately.)
    • Direct image links (if URL ends in .png, .jpeg, etc, embed that image)
    • Embed specific Wikipedia sections, not just the intro paragraph
    • Allow "before" and "after" texts for Wiki/YouTube
    • Can write full content of a very short Nutshell right in the link. (good for "hint systems")
    • A general "plug-in" system so that 1) I don't have a giant if-elseif-elseif statement for handling Wikipedia/YouTube/Vimeo/Wiktionary/Images/etc, and 2) other folks can write their own plug-ins.
  • Allowing very limited styling of content in Nutshells. (the problem is to avoid cross-site vandalism that spills outside of the bubble. So, maybe only background, color, font-size, and float?)
  • An easy tool to make Nutshell links with advanced features, rather than making you go through the documentation & test it in the Try Nutshell demo
  • [I DO NOT LIKE THIS IDEA, BUT AM LISTING IT COZ IT'LL BE REQUESTED A LOT]: Configuration option to show bubbles on hover, hide on mouse-out? (May suck for long, recursive nutshells. And mouse-out seems very fragile โ€“ move cursor 1px and whoops 3 layers of explanation vanish โ€“ plus, won't work on mobile anyway...)
  • Put this on npm? For "serious developer" points.

Advanced features & options

Configuring Nutshell

After including Nutshell (e.g. where you put <script src="nutshell.js"><script>), you can optionally configure Nutshell by immediately calling Nutshell.setOptions afterwards, like so:

<script>
Nutshell.setOptions({
    startOnLoad: true, // Start Nutshell on load? (default: true)
    lang: 'en', // Language (default: 'en', which is English)
    dontEmbedHeadings: false, // If 'true', removes the "embed this as a nutshell" option on headings
});
</script>

There are currently 3 options:

startOnLoad (default: true). Set this to false if you don't want Nutshell to immediately run on page load. (e.g. if your article is asynchronously loaded). Later, to actually start Nutshell, call:

Nutshell.start();

By default, Nutshell tries to convert the whole page. To limit Nutshell to converting just a container/element, call:

Nutshell.start(element);

lang (default: 'en'). If Nutshell supports your language, you can make Nutshell speak it by setting lang to your language's two-letter code. (If you're comfortable with programming/Github, see how you can help translate Nutshell)

dontEmbedHeadings (default: false). When false (by default), it puts an "embed this" button next to all headings on your page, like so:

When set to true, that button does not show up.

Want to change Nutshell's style? Just put CSS after the Nutshell script! To see the classes Nutshell uses (all prepended .nutshell-*), look at Nutshell.defaultStyle in nutshell.js.

For example, this turns the pretty dotted-lines under expandables (the default) into big ugly marker-lines:

<script src="nutshell.js"></script>
<style>
.nutshell-expandable{
    border-bottom: solid 10px;
}
</style>

Stuff you can put in embedded sections

For security reasons, Nutshell can't allow everything to be embedded. But Nutshell does allow: iframes (for interactive content & fun stuff), img, audio, and video.

iframe: Scripts will be allowed, but it cannot access the top page (duh) or call alert() or stuff.

img: Images! The big thing to mention is there's a hack for making images float left/right (like in Wiki articles): add the attribute data-float="left" or data-float="right" to the <img/>. (Direct inline styling is not currently allowed, for security/vandalism reasons. Don't want someone adding position:fixed; z-index:9999; background:url(goatse.jpeg);...)

audio and video: just use as per normal.

Hiding Headings

What if you want write a section for a Nutshell bubble, but don't want the section to appear by itself, without being manually clicked & expanded? (e.g. for hint systems)

If you put a : at the start of a heading, that whole section will be collapsed into an expandable link when Nutshell starts:

If you put :x at the start of a heading, that whole section will be invisible. (But you can still include it elsewhere!)

Other ways to set embedded-expanded content

Remember, you can test all of these in the Try Nutshell demo! The below examples are written in Markdown for convenience, but will work with rich text & raw HTML too.

Section from the same page: # followed by the text of the section's heading โ€“ capitalization, spaces, and punctuation don't matter.

[:dont forget the colon](#SectionHeading)

Section from different page: URL, then # and heading:

[:unsolicited advice](https://ncase.me/faq/#GoodMentalHealth)

Entire article from a page: URL, without # and heading.

[:a whole story](https://blog.ncase.me/parable-of-the-hill-climber/)

Drop the last X paragraphs from a Section: For example, if the original article has a few paragraphs segueing to the next section (which you're not including), you can drop them by adding &cut=[integer] to the end of the link, and it'll drop [integer] number of paragraphs from the end.

[:drop the 2-paragraph segue](url#Heading&cut=2)

Add content before/after an embedded Section: If you want to give context to a section. And yes, you can add recursive nutshells in there! e.g. put some "prerequisite knowledge Nutshells" before the embedded snippet, and some commentary tying it to your main article after the embedded snippet.

To do this, use &before=[content] and/or &after=[content] to the end of your link. The content can be written as text or Markdown. ANNOYING NOTE: You have to run encodeURIComponent on your content before putting it in the link, e.g. [:nutshell](#Nutshell) must become %5B%3Anutshell%5D(%23Nutshell). Use this encoding tool.

Example:

[:controversial](url#Heading&before=RETWEETS%20ARE%20NOT%20ENDORSEMENTS&after=AGAIN,%20I%20DO NOT%20NECESSARILY%20ENDORSE%20THIS)

Example with recursive nutshell in 'before': (note that it's gone through encodeURIComponent)

[:quantum computing](url#Heading&before=First%20you%20need%20to%20know%20about%20%5B%3Aquantum%20mechanics%5D(%23qm))

... I oughta make an easier tool for this, huh.

Section using text-search, not heading: The snippet you want to embed isn't under a convenient heading? You can also get snippets by text-search!

#start=[text] โ€“ Gets FIRST paragraph containing that text (ignoring capitalization/spaces/punctuation)

#start=[text]&length=[integer] โ€“ Same, but also gets the specified number of paragraphs afterwards (including the first paragraph).

#start=[start-text]&end=[end-text] โ€“ Same, but also gets all paragraphs up until the first paragraph containing [end-text]. (again, ignoring capitalization/spaces/punctuation)

Note [text] might need encodeURIComponent, especially if it has punctuation. But Nutshell matches text ignoring punctuation/spaces, so you can just drop them all.

Example: From my blog post on learning-through-multimedia, getting the content between "I make games" and "keep it invisible".

[:Expertise Reversal](https://blog.ncase.me/curse-of-the-chocolate-covered-broccoli-or-emotion-in-learning/#start=imakegames&end=keepitinvisible)


k that's all I have for now, thx bye.

๐Ÿ’– My website ยท ๐Ÿ’ธ My Patreon

More Repositories

1

trust

An interactive guide to the game theory of cooperation
JavaScript
5,682
star
2

loopy

A tool for thinking in systems
JavaScript
1,617
star
3

polygons

A playable post on how harmless choices can make a harmful world.
JavaScript
1,328
star
4

wbwwb

We Become What We Behold โ€“ a minigame about the news!
JavaScript
1,140
star
5

sight-and-light

A programming tutorial for sight & light
HTML
1,049
star
6

nothing-to-hide

All the newest work on Nothing To Hide goes here. It's not clean, it's not organized, but it's *everything*.
JavaScript
773
star
7

joy

make happy little programs
JavaScript
561
star
8

crowds

The Wisdom and/or Madness of the Crowds
HTML
432
star
9

anxiety

JavaScript
400
star
10

fireflies

Fireflies: an example of emergence
JavaScript
335
star
11

coming-out-simulator-2014

Coming Out Simulator 2014
JavaScript
304
star
12

remember

An interactive comic on Spaced Repetition
HTML
303
star
13

door

A Valentine's Day one-minute minigame
JavaScript
242
star
14

covid-19

COVID-19 Futures, Explained With Playable Simulations
HTML
233
star
15

ballot

An interactive guide to alternative voting systems
HTML
213
star
16

neurons

Neurotic Neurons, an interactive explanation.
JavaScript
199
star
17

simulating

An interactive guide to thinking in systems!
JavaScript
185
star
18

crowdfunding-tuts

Make your own Crowdfunding Site: Tutorial & Source Code
JavaScript
164
star
19

ncase.github.io

my personal site, fo' realz
HTML
137
star
20

sim

Relaunch of EMOJI SIMULATOR ๐Ÿ˜˜
JavaScript
85
star
21

matrix

Learn with THE MATRIX
JavaScript
74
star
22

anxiety-demo

AHHHHH!
JavaScript
74
star
23

mental-health

Mental Health Tips (ft. Anxiety Wolf)
HTML
70
star
24

nutshell-beta

Nutshell Beta!
JavaScript
43
star
25

attractors

prototypin' shtuff
HTML
35
star
26

blog

This is my bloooggggggggg
JavaScript
32
star
27

contact-tracing

A comic to explain how contact tracing apps can beat COVID-19 *and* Big Brother
HTML
31
star
28

emoji-prototype

emoji-based artificial life, coz why not
JavaScript
24
star
29

SocialMinusSpying

Social sharing buttons that don't spy on your audience.
JavaScript
24
star
30

StanfordTalk

how to explain things ะฏEAL good
HTML
21
star
31

experiment-stats

A short experiment on expectation failure & learning
HTML
20
star
32

nothide-prototype

The polished prototype for Nothing to Hide
JavaScript
17
star
33

anime

I AM BECOME ANIME
JavaScript
15
star
34

NG.js

NG.JS - An HTML5 port of the Newgrounds Flash API.
JavaScript
14
star
35

birds

Angry Physics! A demonstration of See, Model, Predict
JavaScript
14
star
36

sprite2gif

A web app to convert spritesheets to gifs, aw yiss!
JavaScript
12
star
37

improv-wip

Improv JS Work-in-Progress
JavaScript
12
star
38

bees

BEES
JavaScript
11
star
39

conversation

A conversation engine in the style of The Walking Dead games
JavaScript
10
star
40

Pony-Wings

An HTML5 clone of Tiny Wings, except with ponies.
JavaScript
9
star
41

thanks

WALL! OF! THANKS!
HTML
9
star
42

ncase.me

My tiny website at ncase.me
CSS
9
star
43

cos

Coming Out Simulator - Mobile web version
JavaScript
8
star
44

newgrounds-js

A Javascript implementation of the Newgrounds API
JavaScript
8
star
45

crowds-prototype

the wisdom and/or madness of crowds
JavaScript
8
star
46

trust-hu

Hungarian translation of The Evolution of Trust
JavaScript
7
star
47

learn-wip

Learn How To Learn: WIP
JavaScript
6
star
48

learning

HTML
5
star
49

commonly.cc

Commonly.cc, a marketplace to unlock assets for the public domain
JavaScript
5
star
50

selfies

a game about journalistic ethics
JavaScript
5
star
51

neuron-prototype

a test thingy about neurons, boop boop
JavaScript
5
star
52

OVC2016

Slides & links for my OpenVizConf 2016 talk!
HTML
5
star
53

gamer

a game about gamers
JavaScript
5
star
54

campfire

an interactive story maker, with a focus on modability
JavaScript
5
star
55

nothing-to-browse

The Nothing To Hide Frontpage
HTML
5
star
56

forest-wip

(WIP) An interactive essay on understanding the world's complex systems, I guess
JavaScript
5
star
57

easy-easel

Yet another Canvas drawing app, except it exports to EaselJS code
JavaScript
5
star
58

polygons-es

Spanish translation of Parable of the Polygons, by David T Marchand
JavaScript
5
star
59

crossbreed.js

Multiple Inheritance in Javascript
JavaScript
5
star
60

polygons-pentagons

Pentagon remix, by dncnmcdougall
JavaScript
4
star
61

ink

I AM INK - A 2.5D VR Animation
JavaScript
4
star
62

anypay.js

Anypay.js - Pay what you want, however you want.
JavaScript
4
star
63

vr-comic

Virtual Reality comic - horizontal scrolling test
4
star
64

polygons-de

German translation of Parable of the Polygons
JavaScript
4
star
65

polarization-wip

Simulation of political polarization, WIP
JavaScript
4
star
66

double-slit

A tiny Double Slit sim, for Mithuna The Friendo
JavaScript
4
star
67

fireflies-de

German translation for Fireflies
JavaScript
3
star
68

simulating-wip

WIP for my next interactive essay, yayyy
JavaScript
3
star
69

vr

MY VR EXPERIMENTS, WHOO
JavaScript
3
star
70

poll-stats-june-2018

really half-assed stats
JavaScript
3
star
71

2.5D-VR-Tests

2.5D VR Tests, obviously
JavaScript
3
star
72

cccheckout

Your one-stop shop to download & attribute CC works from across the internet.
JavaScript
3
star
73

gamedev-garage

The Gamedev Garage Sale's code, open-sourced!
JavaScript
3
star
74

wbwwb-de

German translation for We Become What We Behold (Wir Werden, Was Wir Sehen)
JavaScript
3
star
75

hacking-the-government

A tiny experiment to hack gov data, with Shidash's help
JavaScript
3
star
76

pug

Pavlov's Pug
JavaScript
3
star
77

update-9-aug-2019

2
star
78

trust-et

Estonian translation (by Krista Vaabel)
JavaScript
2
star
79

polygons-pt-br

Brazilian Translation of PotP
JavaScript
2
star
80

fireflies-pt-br

Portuguese (Brazilian) translation of Fireflies
JavaScript
2
star
81

polygons-fr

French translation of Parable of the Polygons
HTML
2
star
82

network-prototype

network sim thingy prototype
JavaScript
2
star
83

sccv

We Become What We Behold (Italian Translation)
JavaScript
2
star
84

nothide-blog

Nothing To Hide devblog
CSS
2
star
85

the-race-to-vr

blah blah blah blah
JavaScript
2
star
86

trust-bg

Bulgarian translation of Evolution o' Trust
JavaScript
2
star
87

eyeo2016

My EyeO 2016 Talk
2
star
88

polygons-nl

Dutch translation of Parable of the Polygons
HTML
2
star
89

polygons-hu

Hungarian translation for Parable of the Polygons
JavaScript
2
star
90

wbwwb-ar

Arabic translation of We Become What We Behold, thx to @_alexanderClay
JavaScript
2
star
91

polygons-hi

Hindi translation of Parable of the Polygons (by @anandapurv)
JavaScript
2
star
92

hackysack

JavaScript
2
star
93

px

Embed user-generated pixel art into your sites and games
JavaScript
2
star
94

cuttingedge-craftyy

The Cutting-edge Craftyy
JavaScript
2
star
95

nothing-to-art

Nothing To Hide Art Bundle
JavaScript
2
star
96

topology

Topology shenanigans with Rin Ray
2
star
97

secret

shhh, this is a seeeeecret
JavaScript
2
star
98

prison-wip

[WIP] systems, stories, and statistics on Mass Incarceration
JavaScript
2
star
99

subbed

The post-sub page for the Nicky Newsletter
HTML
2
star
100

ncase-credits

where supporter credits & newsletter signup go
HTML
2
star