Unlike GHCi, rather than one definition or statement or expression at a time,
we accept an arbitrary mix of them. This is almost the same, but it does mean
that if there is a parse error anywhere then nothing happens.
== AsciiDoctor ==
For marking up text, we use AsciiDoc instead of Markdown.
We rely on `asciidoctor.min.js` from
* https://github.com/asciidoctor/asciidoctor.js/releases
By trial and error, I figured out that after including this script, the
following should be called:
----------------------------------------------------------------
Asciidoctor$$module$build$asciidoctor_browser();
----------------------------------------------------------------
and then
https://mrduguo.github.io/asciidoctor.org/docs/install-and-use-asciidoctorjs/[the
official instructions] work as advertised. For example:
----------------------------------------------------------------
element.innerHTML = Opal.Asciidoctor.$convert(src, Opal.hash2(['attributes'], {'attributes': ['showtitle']}));
----------------------------------------------------------------
== MathJax ==
When running an AsciiDoc cell, after calling AsciiDoctor, we call MathJax to
render equations.
I prefer indicating equations with just backslashes and parentheses or square
brackets to AsciiDoctor's more verbose syntax, but sometimes this causes issues
with unwanted AsciiDoc substitutions. When needed, we work around this issue
with AsciiDoc's passthrough mechanism.
When our page loads, our `init()` function renders AsciiDoc snippets with the
JavaScript port of AsciiDoctor, and calls MathJax to render any equations. We
ensure MathJax has already been initialized by calling `init()` after MathJax
is ready.
----------------------------------------------------------------
window.MathJax = {
startup: {
ready: () => {
MathJax.startup.defaultReady();
init();
}
}
};
----------------------------------------------------------------
However, another race arises. These lines only work if evaluated before loading
MathJax. On other pages, we load MathJax in the head section, so the browser
can fetch it in parallel as early as possible. For pages like this one, we load
MathJax last.
== Nonstandard Output ==
Tired of boring text output? Then call `jsEval` to, say, modify the HTML DOM.
The JavaScript variable `repl.outdiv` refers to a DIV element suitable for
placing output, as it is refreshed every run.