Skip to content
Samuel Fang edited this page Jul 3, 2021 · 5 revisions

Requirements

For development & deployment:

  • node.js

The generated JSON files can be hosted on any standard web server.

Overview

The JSON version of SICP JS converts the WEB version of SICP JS into JSON files so that they can be easily processed by other programs.

Generating JSON files

yarn json

JSON files will be in the /json folder.

Deployment to Local Server

yarn json
yarn prepare
yarn try

Files can be accessed by visiting localhost:8080/json/FILENAME.json, where FILENAME is the filename as shown in the /json folder.

Accessing on source-academy.github.io

The JSON files can also be accessed on source-academy.github.io/sicp/json/FILENAME.json.

To deploy on your own GitHub pages domain, run the deploy-pages GitHub action and replace source-academy.github.io with your own domain name.

Structure of the JSON files

The JSON files have a tree like structure, with objects on the same level (same array) being sibling nodes and objects nested within other objects are child nodes.

The root of the JSON file is an array containing one or more objects. Each object represents a node and has the following structure:

{
  tag: Name of Node
  body: Contents of node
  ⋮ (other attributes if needed)
  child: [{...obj}]
}

The following sections document the structure of the different objects. Each object has a tag attribute that is omitted for clarity. A ? beside an attribute is used to indicate an optional attribute.

#text

An object containing pure text.

Attributes

  • body: text, string

TEXT

A paragraph of text.

Attributes

  • id: id, string
  • child: obj[]

TITLE

Title of a section.

Attributes

  • id: id, string
  • body: title, string

OL, UL, LI

  • OL: Ordered List
  • UL: Unordered List
  • LI: List Item

OL and UL objects contain an array of LI objects under the attribute child.

OL/UL Attributes

  • body: title, string
  • child: LI[]

LI Attributes

  • child: obj[]

TABLE, TR, TD

Similar to tables in html, A table contains some TR (table row) and each TR contains some TD (table data).

TABLE Attributes

  • child: TR[]

TR Attributes

  • child: TD[]

TD Attributes

  • child: obj[]

LATEX, META, METAPHRASE

Children to be formatted using LaTeX. For METAPHRASE tags, a < > is to be added surrounding the text. LATEX is displayed as a block while LATEXINLINE, META and METAPHRASE are displayed inline.

Attributes

  • child: text to format, obj[]

LINK, REF, FOOTNOTEREF

Links to other content. LINK links to an external page, REF links to a section on the same page and FOOTNOTEREF links to a footnote and is to be displayed in superscript.

Attributes

  • id: id, string
  • href: link, string
  • body: text to display, string

EPIGRAPH

A Blockquote.

Attributes

  • author?: author, string
  • title?: title, string
  • date?: date, string
  • child: content of blockquote, obj[]

Exercise

An exercise with or without a solution

Attributes

  • id: id, string
  • title: title, string
  • child: exercise question, obj[]
  • solution?: exercise solution, obj[]

DISPLAYFOOTNOTE

Footnote to display.

Attributes

  • count: one-based index of footnote, integer
  • id: id, string
  • href: link to FOOTNOTE-REF, string
  • child: content of footnote, obj[]

REFERENCE

A reference in the reference page.

Attributes

  • child: obj[]

BR

This tags should be replaced with a line break.

B, EM, JAVASCRIPTINLINE, TT

These tags should apply styling to their child components.

  • B - Bold
  • EM - Emphasis
  • JAVASCRIPTINLINE - Inline javascript
  • TT - Generic Code

Attributes

  • child: obj[]

Figure

A figure containing either image src, table or snippet. It may also have a caption.

Attributes

  • id: id, string
  • scale?: scale of image, string (e.g. 50%)
  • src?: src of image, string
  • snippet?: snippet, obj
  • table?: table, obj
  • captionName?: name of caption, string
  • captionBody?: content of caption, obj[]

Snippet

A code snippet. If eval property is false, the code block should not be evaluated. if latex property is true, the code block should be parsed using latex. eval and latex cannot be both true at the same time.

Attributes

  • id: id, string
  • body: code in plain text, string
  • eval: eval flag, boolean
  • latex: latex flag, boolean
  • output?: output of program, string
  • program: compressed string of full program, string
  • prependLength: length of prepend (may be 0), number