?
u
/
p
1-9
Ecmarkup is a number of custom elements and a toolchain suitable for specifying semantics for ECMAScript and other programming languages.
Ecmarkup offers the following conveniences (among many others):
This document is itself written using Ecmarkup. Its source can be viewed on github.
$ npm install -g ecmarkup
$ ecmarkup --help
$ ecmarkup spec.html out.html
Build options and document options can be passed in via the command line or specified in the
Command Line Option | Front-Matter Key | Description |
---|---|---|
--watch | Rebuild when files change. | |
--verbose | Print verbose logging info. | |
--write-biblio | Emit a biblio file to the specified path. | |
--assets | assets | "none" for no CSS/JS/etc, "inline" for inline CSS/JS/etc, "external" for external CSS/JS/etc. |
--assets-dir | assetsDir | Directory in which to place assets when using --assets=external . |
--lint-spec | lintSpec | Enforce some style and correctness checks. |
--error-formatter | The eslint formatter to be used for printing warnings and errors when using --verbose . Either the name of a built-in eslint formatter or the package name of an installed eslint compatible formatter. | |
--strict | Exit with an error if there are warnings. Cannot be used with --watch . | |
--multipage | Emit a distinct page for each top-level clause. |
Command Line Option | Front-Matter Key | Description |
---|---|---|
title | Document title, for example "ECMAScript 2016" or "Async Functions". | |
status | Document status. Can be "proposal", "draft", or "standard". Defaults to "proposal". | |
stage | TC39 proposal stage. If present and status is "proposal", version defaults to "Stage stage Draft". | |
version | Document version, for example "6<sup>th</sup> Edition" (which renders like "6th Edition") or "Draft 1". | |
date | Timestamp of document rendering, used for various pieces of boilerplate. Defaults to the value of the SOURCE_DATE_EPOCH environment variable (as a number of second since the POSIX epoch) if it exists, otherwise to the current date and time. | |
shortname | Document shortname, for example "ECMA-262". If present and status is "draft", version defaults to "Draft shortname". | |
description | Brief description to be used for link previews in social media and the like. | |
location | URL of this document. Used in conjunction with the biblio file to support inbound references from other documents. | |
copyright | Emit copyright and software license information. Boolean, default true. | |
contributors | Contributors to this specification, i.e. those who own the copyright. If your proposal includes text from any Ecma specification, this should include "Ecma International". | |
--no-toc | toc | Emit table of contents. Boolean, default true. |
--old-toc | oldToc | Emit the table of contents at the top of the document rather than as a side pane. Boolean, default false. |
--load-biblio | extraBiblios | Extra biblio.json file(s) to load. This should contain either an object as exported by --write-biblio or an array of such objects. |
boilerplate | An object with address and/or copyright and/or license fields containing paths to files containing the corresponding content for populating an element with class "copyright-and-software-license" (or if not found, an appended copyright is true. Absent fields are assumed to reference files in a "boilerplate" directory sibling of the directory containing the ecmarkup executable. | |
--mark-effects | markEffects | Propagate and render effects like "user code". |
Ecmarkup requires CSS styles and, if you're using the sidebar table of contents, javascript as well. By default CSS and JS dependencies are inlined into the document. You can override this by setting assets to "none" (for example if you want to manually link to external assets). Passing cssOut and jsOut will write the respective files to disk at the given path.
There are a large number of features in Ecmarkup. Detailed documentation can be found in later sections. This section provides a high-level overview of what capabilities are available and when to use them.
Notational Convention | Ecmarkup Functionality |
---|---|
Clauses | |
Algorithms | |
Mathematical expressions | |
Notes | |
Figures (such as images) | |
Tables | |
Examples | |
Grammar | |
Cross-references |
There are also a number of elements and corresponding Ecmarkdown syntax to give inline styles to various parts of your document in accordance with ECMAScript conventions. More detail on Ecmarkdown syntax can be found on its readme.
Notational Convention | Ecmarkdown Syntax | Ecmarkup Functionality |
---|---|---|
Variables, such as those in defined in algorithms, parameters in abstract operations, etc. | _variable_ |
<var>variable</var> |
ECMAScript Language Type Values, eg. |
*TypeError* |
<emu-val>TypeError</emu-val> |
Specification types and their instances, eg. |
~throw~ |
<emu-const>throw<emu-const> |
Source Code, eg. Function.prototype . |
`code` |
<code>code</code> |
Non-terminal references, eg. as |
|FunctionExpression| |
<emu-nt>FunctionExpression</emu-nt> |
There are a number of settings that allow customizations or enable generation of boilerplate. To add metadata to your document, use yaml syntax inside a <pre class="metadata">
element somewhere in the root of your document. See --help
).
Some metadata can also be passed on the command line, for example --no-toc
. Such options take precedence over embedded metadata.
<pre class="metadata">
title: Document 1
toc: false
</pre>
Clauses are referenced using their id and are numbered automatically based on document position. Ecmarkdown syntax can be used in descendent text nodes as well. Text nodes are parsed as Ecmarkdown Fragments.
Non-normative introductory information.
id: Clause id. Must be unique.
aoid: Abstract operation ID. A unique name identifying this clause as an abstract operation. Algorithm steps will auto-link calls to this abstract operation to this clause. If left blank, the aoid will be set to the id of this clause.
Normative clause.
id: Clause id. Must be unique.
example: If present, the clause is an example.
legacy: If present, the clause is Legacy.
normative-optional: If present, the clause is Normative Optional.
number: Optional: An explicit clause number, overriding the default auto-incrementing number. Can be a nested number, as in number="2.1"
.
type: Optional: Type of feature described by the clause.
aoid: Abstract operation ID. A unique name identifying this clause as an abstract operation. Algorithm steps will auto-link calls to this abstract operation to this clause. If left blank, the aoid will be set to the id of this clause. When a
A clause describing an operation or method may have a structured header to document its signature and metadata. Such a structure consists of:
<h1>
element containing the name of the operation followed by a parenthesized list of parameters, each appearing on a comma-terminated line of its own and consisting of a name and value constraints separated by a colon and optionally preceded with "optional"<dl>
element with class "header" and a collection of optional key-value pairs expressed using <dt>
and <dd>
elements:
<emu-clause id="example-normative-optional" type="abstract operation" normative-optional example>
<h1>
ExampleOperation (
_S_: a String,
optional _length_: a non-negative integer,
)
</h1>
<dl class="header">
<dt>description</dt>
<dd>It returns a List of the code points of the first _length_ grapheme clusters of _S_ using the host environment's current locale, or all code points when _length_ is not present.</dd>
</dl>
<p>This clause is normative optional.</p>
</emu-clause>
Annex clause.
normative: If present, annex is normative. Default is non-normative.
id: Clause id. Must be unique.
aoid: Abstract operation ID. A unique name identifying this clause as an abstract operation. Algorithm steps will auto-link calls to this abstract operation to this clause. If left blank, the aoid will be set to the id of this clause.
Terms can be defined using the <dfn>
element. Any uses of that term will be automatically linked to the clause containing the definition, or, if the <dfn>
element has an id
, to the <dfn>
itself. This can be suppressed with the emu-not-ref
element.
When the term starts with a lowercase English letter, usages of the term with the first letter capitalized will also link.
variants: If present, specifies other variants of the term (such as plural forms). Multiple variants are separated by commas with optional whitespace.
<p>A <dfn id="swordfish" variants="swordfishes,broadbill,broadbills,Xiphias gladius">swordfish</dfn> is a large fish characterized by a long, pointed bill.</p>
<p>The Latin name for swordfishes, <em>Xiphias gladius</em>, comes from the Greek word "ξίφος" (xiphos, "sword") and from the Latin word "gladius" ("sword").</p>
Abstract operations can be marked as having effects that propagate to their invocation sites. Subject to the following rules, calls to such operations are given a class of the effect name prefixed with “e-”. When using markEffects
, the CSS includes styling for the "user-code" effect via class name e-user-code
that is off by default but can be togged by pressing u.
Within an algorithm, an emu-meta
element enclosing an operation invocation can be used to indicate either the origination of effects or the absence of effects using a list of effect names separated by commas with optional whitespace in an effects or suppress-effects attribute (respectively).
1. Let _value_ be ? <emu-meta effects="user-code">_O_.[[Get]]</emu-meta>(_P_, _O_).
1. Let _primValue_ be ? ToPrimitive(_value_, ~number~).
1. Let _stringValue_ be ? <emu-meta suppress-effects="user-code">ToString(_primValue_)</emu-meta>.
Effects do not normally propagate to callsites marked as infallibly non-abrupt with !
. Such sites must be manually marked with emu-meta
.
When a step or its substeps have effects but those effects should not imply that the containing algorithm has the same effects, propagation may be prevented using a [fence-effects="user-code"]
annotation at the begining of the step. This implicitly applies to steps which define abstract closures.
It is also possible to associate effects at the level of an entire operation (for example, because it is not defined with algorithm steps) by adding to its structured header an effects entry.
<emu-clause id="sec-effect" type="abstract operation">
<h1>Effect ()</h1>
<dl class="header"></dl>
<emu-alg>
1. <emu-meta effects="user-code">Call user code.</emu-meta>
</emu-alg>
</emu-clause>
<emu-clause id="sec-transitive-effect" type="abstract operation">
<h1>TransitiveEffect ()</h1>
<dl class="header"></dl>
<emu-alg>
1. Perform Effect().
</emu-alg>
</emu-clause>
Algorithm steps. Should not contain any HTML. The node's textContent is parsed as an Ecmarkdown document. Additionally, calls to abstract operations inside algorithm steps are automatically linked to their definitions by first checking for any clauses or algorithms with the appropriate aoid in the current spec, and afterwards checking any linked bibliography files.
Algorithm steps can be annotated with additional metadata as summarized in
example: If present, the element is an example.
replaces-step: If present, references a step to replace by its
<emu-alg>
1. Let _length_ be 0.
1. Let _node_ be this |ListNode|.
1. Repeat, while _node_ is not *undefined*,
1. Set _node_ to NextNode of _node_.
1. [id="step-example-label"] Set _length_ to _length_ + 1.
1. Return _length_.
</emu-alg>
<p>The following is an alernative definition of step <emu-xref href="#step-example-label"></emu-xref>.</p>
<emu-alg replaces-step="step-example-label">
1. Set _length_ to _length_ + 1.
1. Let _weight_ be GetWeight of _node_.
1. If _length_ = 10<sup>9</sup> or _weight_ > 2<sup>_length_ + 1</sup>, then
1. NOTE: This is an out-of-bounds state.
1. If _ignoreErrors_ is not *true*, then
1. Throw a *RangeError* exception.
1. Set _hadError_ to *true*.
</emu-alg>
Data | Description | Example Syntax |
---|---|---|
Provide an id for referencing an individual step. | [id="step-label"] |
|
Inform the linter of the existence of a variable. | [declared="x"] |
|
Originate, suppress, or constrain the scope of effects. | <emu-meta> , [fence-effects="user-code"] |
|
Step optionality | Mark a step as deprecated, normative-optional, or legacy. | [normative-optional] |
Each step can be given an id for reference by
<emu-alg>
1. [id="step-example-internal"] Let _obj_ be OrdinaryObjectCreate(*null*).
</emu-alg>
The linter checks that each used variable in an algorithm step is declared earlier. It recognizes most common forms of declaration automatically, but in case there is a declaration which is not automatically inferred, a variable can be marked as declared for the purposes of this analysis by adding a [declared="v"]
attribute at the start of the step. Multiple variables can be separated by commas with optional whitespace.
Note that the [declared="v"]
attribute must be at the beginning of the step, including before any <ins>
tags.
<emu-alg>
1. [declared="x"] Suppose the existence of _x_.
</emu-alg>
An equation, similar to those found in ES6 Year Number.
aoid: If present, an abstract operation id defined by this equation.
id: If present, links will go directly to the eqn definition. Otherwise, links go to the parent clause.
Non-normative explanatory text. Comes in two types - regular notes and Editor's notes. Regular notes are intended for the implementers and end users of this specification. Editor's notes are notes to and from the Editors and will generally be removed prior to a specification being finalized and ratified.
type: The type of note, either blank or "editor".
<p>For authentication only, servers and clients MUST support SASL Salted Challenge Response Authentication Mechanism [SCRAM].</p>
<emu-note>But we know you won't.</emu-note>
<emu-note type="editor">This joke brought to you by RFC6919.</emu-note>
Cross-reference another clause, production, note, example, abstract operation, or labeled step. If the text content of this element is empty, a suitable default is used. The title
attribute controls this default - when present, clauses are referred to using their title rather than number. This also applies to examples which are indexed first by their containing clause and then their example number.
Cross-references to an id check for clauses, productions, examples, and steps in this order. For each type, the local document is consulted before looking for external sources.
href: Optional: URL of the target clause, production, or example to cross-reference, interpreted relative to the containing document.
title: Optional: If present, xref will be filled in with the referenced clause's title. Otherwise, the clause's section number is used.
aoid: Optional: aoid of an abstract operation to reference.
One of aoid or href must be specified.
<p>The clause element is specified in <emu-xref href="#emu-clause"></emu-xref>.</p>
<p>See <emu-xref href="#emu-note" title></emu-xref> for information on the emu-note element.</p>
<p>The <emu-xref href="#emu-biblio">biblio element</emu-xref> supports xref to external specs.</p>
<p><emu-xref aoid="Get"></emu-xref> is an abstract operation from ES6</p>
<p><emu-alg>1. [id="step-label-example"] Example labeled step.</emu-alg></p>
<p>You can reference step <emu-xref href="#step-label-example"></emu-xref> like this</p>
Suppresses automatic linking to definitions.
<div id="not-ref-section-1">
<p>An <dfn>example</dfn> is used for illustrative purposes.</p>
</div>
<div id="not-ref-section-2">
<p>When a word defined in another section (or algorithm step) is used, as in this example, it is normally automatically linked to the section containing the definition.</p>
<p>When such a word should not be automatically linked, for <emu-not-ref>example</emu-not-ref> when using its colloquial definition, it can be wrapped with this tag to surpress the automatic linking.</p>
</div>
Creates a figure that can be referenced by emu-caption
element.
informative: Optional: If present, the figure is informative. Otherwise it is normative.
<emu-figure>
<emu-caption>Example figure<emu-caption>
[[insert some awesome graphic here, maybe something like figure 2]]
</emu-figure>
Creates a table that can be referenced by emu-caption
element.
caption: Optional: Caption for the example
informative: Optional: If present, the table is informative. Otherwise it is normative.
<emu-table>
<emu-caption>Example table<emu-caption>
<table>
<tr><th>Column 1</th><th>Column 2</th></tr>
<tr><td>Value</td><td>Value 2</td></tr>
<tr><td>Value</td><td>Value 2</td></tr>
<tr><td>Value</td><td>Value 2</td></tr>
<tr><td>Value</td><td>Value 2</td></tr>
</table>
</emu-table>
Creates an informative example that can be referenced by
caption: Optional: Caption for the example
<emu-example caption="Example Example">
This is an example.
</emu-example>
<emu-example caption="Another Example Example">
This is also an example.
</emu-example>
Links a bibliography file. The bibliography file is a JSON document containing URLs for referenced documents along with any algorithms they define.
href: Required: URL of the biblio file, interpreted relative to the containing document.
{
"https://tc39.github.io/ecma262/": [
{
"type": "op",
"id": "sec-returnifabrupt",
"aoid": "ReturnIfAbrupt"
},
{
"type": "op",
"id": "sec-get-o-p",
"aoid": "Get"
}
]
}
spec.emu
<emu-biblio href="./biblio.json"></emu-biblio>
<emu-alg>
1. Let _res_ be Get(_obj_, _key_).
1. ReturnIfAbrupt(_res_).
</emu-alg>
Text inside emu-grammar elements is parsed using Grammarkdown. The syntax is essentially identical to the notational conventions in ECMAScript (minus formatting). See the Grammarkdown readme.
Grammar will be displayed as an inline element flowing with text unless it is the immediate child of an emu-clause-like element.
collapsed: If present, productions are displayed in collapsed format with
example: If present, the element is an example.
primary: Optional: Deprecated in favor of type="definition".
type: Optional: Disposition of the grammar. If absent, it is considered to reference productions defined elsewhere.
<p>
<emu-grammar type="definition" collapsed example>
HexIntegerLiteral :: `0x` HexDigits
</emu-grammar>
is a shorthand for:
</p>
<emu-grammar type="definition" example>
HexIntegerLiteral :: `0` `x` HexDigits
</emu-grammar>
Although discouraged, it is possible to directly specify grammar using the emu-production element and related elements emitted by Grammarkdown.
<emu-production name="DecimalDigit" type="lexical" oneof>
<emu-rhs>0 1 2 3 4 5 6 7 8 9</emu-rhs>
</emu-production>
<emu-production name="Identifier" type="lexical">
<emu-rhs><emu-nt>IdentifierName</emu-nt> <emu-gmod>but not
<emu-nt>ReservedWord</emu-nt></emu-gmod></emu-rhs>
</emu-production>
<emu-production name="SourceCharacter" type="lexical">
<emu-rhs><emu-gprose>any Unicode code point</emu-gprose></emu-rhs>
</emu-production>
<emu-production name="ExpressionStatement" params="Yield">
<emu-rhs>
<emu-gann>lookahead ∉ { <emu-t>{</emu-t>, <emu-t>function</emu-t>,
<emu-t>class</emu-t>, <emu-t>let [</emu-t> }</emu-gann>
</emu-rhs>
</emu-production>
<emu-production name="IterationStatement">
<emu-rhs>for ( <emu-nt>LexicalDeclaration</emu-nt> ; <emu-nt optional>Expression</emu-nt> ;
<emu-nt optional>Expression</emu-nt> ) <emu-nt>Statement</emu-nt></emu-rhs>
</emu-production>
<emu-production name="StatementList" params="Return, In">
<emu-rhs constraints="~Return"><emu-nt>ReturnStatement</emu-nt></emu-rhs>
<emu-rhs><emu-nt>ExpressionStatement</emu-nt></emu-rhs>
</emu-production>
This is the top level element that contains a grammar production associating a shared LHS (left-hand side)
The production will be displayed as an inline element flowing with text unless it is the immediate child of an emu-clause-like element or if its containing emu-grammar element is an immediate child of an emu-clause-like element.
name: Required: Name of the production (i.e. the LHS). Should conform with the syntax of Unicode Standard Annex #31, UAX31-D1 Default Identifier Syntax and not include any underscore (U+005F LOW LINE “_”).
collapsed: If present, the production is displayed in collapsed format with LHS and RHS on the same line.
oneof: If present, the production is a one-of production. See the DecimalDigit example
optional: If present, the LHS is marked as optional.
params: Parameters for this production. Multiple parameters are separated by commas with optional whitespace.
primary: Optional: The production is authoritative and should be the target of references.
type: Optional: Type of production. If absent, the production is considered syntactic.
Describes one right-hand-side alternative of a production. Interior text nodes are split on each space and turned into terminal symbols. For example, the following elements are semantically equivalent:
<emu-rhs>a b c</emu-rhs>
<emu-rhs><emu-t>a</emu-t> <emu-t>b</emu-t> <emu-t>c</emu-t></emu-rhs>
constraints: any constraints for this
a: Optional: alternative id used to reference a particular emu-rhs
elements inside an
References a non-terminal symbol by the name attribute of its
example: If present, the element is an example.
optional: If present, the non-terminal is optional in its containing
params: Parameters for this non-terminal. Multiple parameters are separated by commas with optional whitespace.
References a terminal symbol. No attributes are available. Manual creation of these elements should be unnecessary as they are created automatically inside emu-rhs elements.
Contains well-known modifiers to a right-hand side of a production. The only well-known modifier at present is the "but not" modifier. See the Identifier example
Contains well-known annotations to to a right-hand side of a production. The only well-known modifiers at present are "lookahead" and "empty". See the ExpressionStatement example
Contains any prose text that describes a production. See the SourceCharacter example
References a production or
name: Required: Name of the production to reference.
a: Optional. If present, references a particular
Imports are treated specially in an ecmarkup document. Every import is inlined into its parent document at the location of the import tag. This is useful for breaking your spec document up into many smaller pieces.
href: Required: URL of the document to import, interpreted relative to the document containing the emu-import
.
Old IDs for any element can be stored separated by commas with optional whitespace inside an oldids attribute, allowing links using them to continue working as expected.
The ins
and del
HTML elements can be used to mark insertions and deletions respectively. When adding or removing block content (such as entire list items, paragrpahs, clauses, grammar RHSes, etc.), use a class of "block".
ECMAScript <del>6</del><ins>2015</ins> <del>will be ratified</del><ins>was ratified</ins> in June, 2015.
<emu-production name="HoistableDeclaration">
<emu-rhs><emu-nt>FunctionDeclaration</emu-nt></emu-rhs>
<emu-rhs><emu-nt>GeneratorDeclaration</emu-nt></emu-rhs>
<ins class="block"><emu-rhs><emu-nt>AsyncFunctionDeclaration</emu-nt></emu-rhs></ins>
</emu-production>
Create a code listing using <pre><code>
. The code
element takes a class of javascript
, html
, or any other language provided by highlightjs. Ecmarkup will trim any leading blank lines and also normalize the indentation based on the indentation of the first line.