diff --git a/css/elements.css b/css/elements.css
index 6ed12734..fdf008fe 100644
--- a/css/elements.css
+++ b/css/elements.css
@@ -83,17 +83,27 @@ emu-eqn div:first-child {
emu-note {
display: block;
- margin-left: 5em;
+ margin-left: 6em;
color: #666;
}
emu-note span.note {
text-transform: uppercase;
- margin-left: -5em;
+ margin-left: -6em;
display: block;
float: left;
}
+emu-example {
+ display: block;
+ margin: 1em 3em;
+}
+
+emu-example figure figcaption {
+ margin-top: 0.5em;
+ text-align: left;
+}
+
emu-production {
display: block;
margin-top: 1em;
diff --git a/lib/Clause.js b/lib/Clause.js
index 06640a6b..5aef9dd8 100644
--- a/lib/Clause.js
+++ b/lib/Clause.js
@@ -2,6 +2,7 @@
const CLAUSE_ELEMS = ['EMU-INTRO', 'EMU-CLAUSE', 'EMU-ANNEX'];
const Note = require('./Note');
+const Example = require('./Example');
const emd = require('ecmarkdown');
const utils = require('./utils');
const Builder = require('./Builder');
@@ -56,7 +57,9 @@ module.exports = class Clause extends Builder {
number: this.number
};
- this.notes = this.getNotes();
+ const record = this.getNotesAndExamples();
+ this.notes = record[0];
+ this.examples = record[1];
}
build() {
@@ -69,6 +72,7 @@ module.exports = class Clause extends Builder {
processEmd(this);
this.buildNotes();
+ this.buildExamples();
}
buildNotes() {
@@ -82,8 +86,20 @@ module.exports = class Clause extends Builder {
}
}
- getNotes() {
+ buildExamples() {
+ if (this.examples.length === 1) {
+ this.examples[0].build();
+ } else {
+ // pass along example index
+ this.examples.forEach(function (example, i) {
+ example.build(i + 1);
+ }, this);
+ }
+ }
+
+ getNotesAndExamples() {
const notes = [];
+ const examples = [];
utils.domWalk(this.node, function (child) {
if (CLAUSE_ELEMS.indexOf(child.nodeName) > -1) {
@@ -93,9 +109,13 @@ module.exports = class Clause extends Builder {
if (child.nodeName === 'EMU-NOTE') {
notes.push(new Note(this.spec, child));
}
+
+ if (child.nodeName === 'EMU-EXAMPLE') {
+ examples.push(new Example(this.spec, child, this));
+ }
}.bind(this));
- return notes;
+ return [notes, examples];
}
buildUtils() {
diff --git a/lib/Example.js b/lib/Example.js
new file mode 100644
index 00000000..d5277ce7
--- /dev/null
+++ b/lib/Example.js
@@ -0,0 +1,42 @@
+'use strict';
+const Builder = require('./Builder');
+
+module.exports = class Example extends Builder {
+ constructor(spec, node, clause) {
+ super(spec, node);
+ this.clause = clause;
+ this.caption = this.node.getAttribute('caption');
+ if (this.node.hasAttribute('id')) {
+ this.id = this.node.getAttribute('id');
+ }
+ }
+
+ build(number) {
+ // biblio is added during the build step as we don't know
+ // the number at build time. Could probably be fixed.
+ this.spec.biblio.examples[this.id] = {
+ location: '',
+ id: this.id,
+ number: number || 1,
+ clauseId: this.clause.id
+ };
+
+ this.node.innerHTML = '
To add metadata to your document, use yaml syntax inside a `<pre class=metadata>` element somewhere in the root of your document.
The following table lists the currently supported metadata:
Option | Description |
---|---|
toc | Emit table of contents. Boolean, default true. |
Cross-reference another clause. If the text content of this element is empty, the target clause's section number or title will be used.
+Cross-reference another clause, production, example, or abstract operation. 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, and examples in this order. For each type, the local document is consulted before looking for external sources including the default ES6 biblio.
+href: Required: URL of the target clause to cross-reference. May simply be a fragment identifier (see examples below).
+href: Optional: URL of the target clause, production, or example to cross-reference.
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> will eventually support xref to external specs.</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>
Result
The clause element is specified in
See
The
Creates an informative example. Examples are numbered based on how many are present in the example's containing clause. Can be xrefed by ID using `emu-xref`.
+ +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.
diff --git a/test/example.html b/test/example.html new file mode 100644 index 00000000..25c360bf --- /dev/null +++ b/test/example.html @@ -0,0 +1,24 @@ +toc: false+
Examples outside of clauses aren't processed specially.
+Examples outside of clauses aren't processed specially.
+