This module provides an install()
function for use in the editor's setup
routine. It takes action if and only if we detect that this instance of the
Lurch application is embedded in an iframe, and is thus not a top-level app
intended for users to edit, but an app that is being used in some other
context (e.g., documentation, blog, online book, etc.) where the author of
that site will be providing the application's document content, probably as
an example for the reader to view (and optionally edit). See the
documentation below for the install()
function to learn more about its behavior.
To make it easy for users to embed Lurch documents in an external page, we provide some handy notation, so that they do not need to write the intricate HTML content that is the actual representation of atoms and shells in the TinyMCE editor when Lurch is running. (That would be far too complex for a human author.) Instead, they can use one of the following two notations.
HTML Notation
Ordinary HTML, plus the following extra tags:
<lurch>...</lurch>
, which should contain a single piece of text in Lurch notation, and will be replaced with an Expression atom that contains that notation (in advanced mode).<latex>...</latex>
, which should contain a single piece of LaTeX code, and will be replaced with an ExpositoryMath atom containing the same LaTeX code.<theorem>...</theorem>
,<proof>...</proof>
, and so on, one for every type of Shell subclass that has been registered with the app, and which will be converted into a shell of that subclass, containing whatever is placed inside of the opening and closing tags.
Markdown Notation
Ordinary Markdown, plus the following extra features:
- Any text containing
$...$
will be replaced with a<latex>...</latex>
tag containing the same content, and then processed as in HTML mode, as defined above. - Any inline code block encosed in backticks will be replaced with a
<lurch>...</lurch>
tag containing the same code, which should therefore be in Lurch notation, and will then be processed as in HTML mode, as defined above. - Any blockquote section (each line beginning with
>
) will be replaced by a<proof>...</proof>
tag containing the contents of the blockquote, or a<subproof>...</subproof>
tag instead if it is an inner blockquote (that is, one with a blockquote ancestor).
To make it easy for the outer page to define where copies of the Lurch app should appear, and what they should contain, we provide a script you can import into that outer page, which will do the job automatically. See the embedded.js script for details.
Document headers
As you write a Lurch document, you may want some content to be placed into its document header. For example, you may want some axioms or rules of inference to be stored there so that they are usable in the document, without taking up space in that document.
In both Markdown and HTML formats, the user can create a DIV with the class
"header" to mark a portion of the document as the header. That is, write
<div class="header">
, followed by the contents of the header (over the
course of as many paragraphs as needed), followed by the closing </div>
.
Source
Methods
install(editor)
This function should be called on the TinyMCE's editor during its setup phase. It takes the following actions, to ensure support for a containing page to be able to send a document to this editor for it to load.
- Send a message to the top-level window saying that it's ready to receive data from the containing page, to populate the editor with.
- Install an event handler for messages from the top-level window that expects the document to be shown in the editor. When that document comes, it will be decoded from HTML or Markdown form, which includes interpreting any of the handy codes inside that HTML or Markdown into their correct form for inclusion in the app, as documented below.
- If the user requests that the document be validated after it is shown, we queue up a validation action as well.
Parameters
-
editor
tinymce.editor
the editor in which to embed any document passed to us by our containing page