You will generally want to use Revealables.jl with the hide_input Jupyter extension installed. This extension hides the code cells. Revealables will reveal the output when a button is pressed. If the extension is not installed, then the code will not be hidden. You can unhide the code cells by clicking on the chevron-up icon.
Instructions for installing Jupyter extensions can be found here). If you are using anaconda, which supplies the conda command, you can run the following:
conda install -c conda-forge jupyter_contrib_nbextensions
Then you must run:
jupyter contrib nbextension install --user
jupyter nbextension enable hide_input/main
In [1]:
using Revealables
Run the cells below to generate buttons that will reveal HTML.
In [2]:
revealable("""
# Revealables.jl
Hide and reveal text with the click of a button
""", "Click this button!", false)
Out[2]:
In [3]:
h = Revealable("""
You can use two steps to create a button:
1. Create an instance of a <code>Revealable</code>, which has three fields:
* Markdown (which can include HTML) to display [<code>String</code>]
* the label to use on a button [<code>String</code>]
* whether or not the Markdown should be displayed automatically (`false` by default) [<code>Bool</code>]
2. run the <code>revealable</code> function to create the button.
""", "This is the button's label", false)
revealable(h)
Out[3]:
In [4]:
revealable("""
You can also just run the <code>revealable</code> function
and pass in the same arguments as if you were instantiating
the <code>Revealable</code> type. The same defaults and
options apply.
""", "Another Button!", false)
Out[4]:
In [5]:
variable = "This is an interpolated string!"
formatted = "<font color=blue>This string includes HTML.</font>"
revealable("""
You can include variables in your Revealable by using normal
Julia string interpolation. $variable $formatted You have to escape the characters
\", \$, \\, \\\*, and \# as shown in the code.
""", "Interpolate Variables", false)
Out[5]:
In [6]:
revealable("""There is only an <font color="purple">String argument</font>
passed to this function. The string will be displayed as Markdown,
which can handle many HTML tags.""")
Out[6]:
In [7]:
revealable("""In addition to including HTML and Markdown, you can
format your text through CSS classes. That will require you to
define new classes in your custom.css file.""")
Out[7]:
In [8]:
text = Revealable("""You can encode content using a Caesar cipher
so students can't easily see answers until you give them the password.
There are two ways to encode the Revealable:
* `encode!` (destructive)
* `encode` (returns a new Revealable with the content of the old Revealable encoded)
Likewise, there are two ways to decode the encoded Revealable:
* `decode!` (destructive)
* `decode` (returns a new Revealable with the content of the old Revealable decoded)
You cannot double-encode or double-decode a Revealable. If a Revealable has been encoded,
you cannot encode it again unless it is decoded first.""")
revealable(text)
Out[8]:
In [9]:
encode!(text, "password")
revealable(text)
Out[9]:
In [10]:
decode!(text, "password")
revealable(text)
Out[10]:
In [11]:
revealable("""
The first button won't work.
""", "Broken Button", false)
revealable("""
The second button won't work.
""", "Another Broken Button", false)
revealable("""Only the third button works!
If you know how to fix this, I'd love to learn.""", "Functional Button!", false)
Out[11]:
Also, the Markdown in button output can't display LaTeX.
In [12]:
revealable("""
Markdown doesn't render LaTeX: \$\\frac{3^x}{x-2}\$. Use HTML and less nice formatting instead: (3<sup>x</sup>)/(x-2).
""", "No LaTeX", false)
Out[12]: