Skip to content

Integrate java-runner in place of Trinket #31

Description

@ChrisMayfield

The original LaTeX source included 17 instances of \begin{trinket} spread across chapters 1–5, 7, and 10. When running make trinket, these environments would be wrapped in JavaScript that rendered the code as interactive "trinkets" hosted on https://books.trinket.io/. (When building the pdf version, the trinket environments would render the same as the other code environments.) Trinket.io is being discontinued, so we developed our own java-runner library for rendering interactive code snippets entirely client side. That way we can provide an interactive version of the textbook hosted on our GitHub Pages site.

The purpose of this issue is to add code to the quarto source files and build process to use java-runner. See the README and examples for usage instructions. A live demo is also available.

The following steps are anticipated:

  1. Identify the code snippets that were originally marked with \begin{trinket}. In the quarto files, all of these have been replaced with code fences annotated with {.java language="Java"} and are indistinguishable from other code snippets.
  2. Create an additional annotation to indicate that this snippet should be wrapped in a <script type="text/x-java"> element in the build, causing the snippet to be interactive.
  3. And javarunner.css and javarunner.js to this repo and include them in the build. (They should be included in every HTML page.)
  4. Test that all snippets run correctly in the build output.

The above four steps should bring the book into feature parity with the trinket version. To go the extra mile, we could also do the following:

  1. Identify other code snippets that could be interactive. Trinket required complete programs, but java-runner can run incomplete snippets: if no class or main method is provided, the code snippet is compiled as if it were in a main method. Some snippets would make sense to be interactive, while others would make more sense to remain as static content.
  2. Identify code snippets that could be rendered in a JShell-like REPL environment (<script type="text/x-java-repl">). That way, the reader could see both the code and its output, and the reader could interactively experiment further.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions