Skip to content

Commit bcf387a

Browse files
committed
Add emu-eqn
1 parent d192fbe commit bcf387a

11 files changed

+112
-19
lines changed

css/elements.css

+9
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ emu-alg ol ol ol, ol ol ol ol ol ol {
7272
list-style-type: lower-roman;
7373
}
7474

75+
emu-eqn {
76+
display: block;
77+
margin-left: 4em;
78+
}
79+
80+
emu-eqn div:first-child {
81+
margin-left: -2em;
82+
}
83+
7584
emu-note {
7685
display: block;
7786
margin-left: 5em;

lib/Algorithm.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ const emd = require('ecmarkdown');
66
module.exports = class Algorithm extends Builder {
77
build() {
88
const contents = this.node.innerHTML;
9-
let html = emd.document(contents);
9+
let html = this.autolinkOps(emd.document(contents));
10+
this.node.innerHTML = html;
11+
}
1012

11-
html = html.replace(/([A-Z]\w+)\(/g, function (match, name) {
13+
autolinkOps(contents) {
14+
return contents.replace(/([A-Z]\w+)\(/g, function (match, name) {
1215
let op = this.spec.biblio.ops[name];
1316
if (!op) op = this.spec.externalBiblio.ops[name];
1417
if (!op) return match;
1518

1619
return '<a href="' + op.location + '#' + op.id + '">' + name + '</a>(';
1720
}.bind(this));
18-
19-
this.node.innerHTML = html;
2021
}
2122
};

lib/Eqn.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
const Algorithm = require('./Algorithm');
3+
module.exports = class Eqn extends Algorithm {
4+
constructor(spec, node) {
5+
super(spec, node);
6+
this.aoid = node.getAttribute('aoid');
7+
this.id = this.aoid;
8+
this.spec.biblio.ops[this.aoid] = {
9+
aoid: this.aoid,
10+
id: this.id,
11+
location: '',
12+
};
13+
}
14+
15+
build() {
16+
let contents = this.node.innerHTML;
17+
contents = '<div>' + contents.split(/\r?\n/g)
18+
.filter(function(s) { return s.trim().length > 0; })
19+
.join('</div><div>');
20+
this.node.innerHTML = this.autolinkOps(contents);
21+
}
22+
};

lib/Production.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = class Production extends Builder {
1818
this.rhsesById = {};
1919

2020
const rhses = this.node.querySelectorAll('emu-rhs');
21-
for (const i = 0; i < rhses.length; i++) {
21+
for (let i = 0; i < rhses.length; i++) {
2222
const rhs = new RHS(this.spec, this, rhses[i]);
2323
this.rhses.push(rhs);
2424

lib/Spec.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const Production = require('./Production');
1717
const ProdRef = require('./ProdRef');
1818
const Grammar = require('./Grammar');
1919
const Xref = require('./Xref');
20+
const Eqn = require('./Eqn');
2021

2122
const NO_CLAUSE_AUTOLINK = ['PRE', 'CODE', 'EMU-CLAUSE', 'EMU-ALG', 'EMU-PRODUCTION', 'EMU-GRAMMAR', 'EMU-XREF', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6'];
2223
const clauseTextNodesUnder = utils.textNodesUnder(NO_CLAUSE_AUTOLINK);
@@ -67,16 +68,21 @@ module.exports = class Spec {
6768
elems = selector;
6869
}
6970

71+
const builders = [];
7072
const ps = [];
7173

74+
for (let i = 0; i < elems.length; i++) {
75+
const b = new Builder(this, elems[i]);
76+
builders.push(b);
77+
}
78+
7279
if (opts.buildArgs) {
73-
for (const i = 0; i < elems.length; i++) {
74-
const b = new Builder(this, elems[i]);
75-
ps.push(b.build.apply(b, opts.buildArgs));
80+
for (let i = 0; i < elems.length; i++) {
81+
ps.push(builders[i].build.apply(builders[i], opts.buildArgs));
7682
}
7783
} else {
78-
for (const i = 0; i < elems.length; i++) {
79-
ps.push(new Builder(this, elems[i]).build());
84+
for (let i = 0; i < elems.length; i++) {
85+
ps.push(builders[i].build());
8086
}
8187
}
8288

@@ -89,6 +95,7 @@ module.exports = class Spec {
8995
.then(this.loadBiblios.bind(this))
9096
.then(this.buildAll.bind(this, 'emu-clause, emu-intro, emu-annex', Clause))
9197
.then(this.buildAll.bind(this, 'emu-grammar', Grammar))
98+
.then(this.buildAll.bind(this, 'emu-eqn', Eqn))
9299
.then(this.buildAll.bind(this, 'emu-alg', Algorithm))
93100
.then(this.buildAll.bind(this, 'emu-production', Production))
94101
.then(this.buildAll.bind(this, 'emu-prodref', ProdRef))
@@ -177,7 +184,7 @@ module.exports = class Spec {
177184
highlightCode() {
178185
this._log('Highlighting syntax...');
179186
const codes = this.doc.querySelectorAll('pre code');
180-
for (const i = 0; i < codes.length; i++) {
187+
for (let i = 0; i < codes.length; i++) {
181188
hljs.highlightBlock(codes[i]);
182189
}
183190
}
@@ -214,7 +221,7 @@ module.exports = class Spec {
214221
autolinkWalk(clauseReplacer, autolinkmap, this, this);
215222

216223
const algs = this.doc.getElementsByTagName('emu-alg');
217-
for (const i = 0; i < algs.length; i++) {
224+
for (let i = 0; i < algs.length; i++) {
218225
const alg = algs[i];
219226
autolink(algReplacer, termlinkmap, this, alg);
220227
}
@@ -248,7 +255,7 @@ function autolinkWalk(replacer, autolinkmap, spec, rootClause) {
248255
function autolink(replacer, autolinkmap, spec, node, parentId) {
249256
const textNodes = clauseTextNodesUnder(node);
250257

251-
for (const i = 0; i < textNodes.length; i++) {
258+
for (let i = 0; i < textNodes.length; i++) {
252259
const node = textNodes[i];
253260

254261
const template = spec.doc.createElement('template');

lib/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ exports.domWalk = function (root, cb) {
1616
const childNodes = root.childNodes;
1717
const childLen = childNodes.length;
1818

19-
for (const i = 0; i < childLen; i++) {
19+
for (let i = 0; i < childLen; i++) {
2020
const node = childNodes[i];
2121
if (node.nodeType !== 1) continue;
2222

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ecmarkup",
3-
"version": "2.0.0-beta1",
3+
"version": "2.0.0-beta2",
44
"description": "Custom element definitions and core utilities for markup that specifies ECMAScript and related technologies.",
55
"main": "lib/ecmarkup.js",
66
"scripts": {

spec/biblio.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
{
22
"http://people.mozilla.org/~jorendorff/es6-draft.html": {
3-
"abstract operations": {
4-
"ReturnIfAbrupt": "#sec-returnifabrupt",
5-
"Get": "#sec-get-o-p"
3+
"ops": {
4+
"ReturnIfAbrupt": {
5+
"id": "sec-returnifabrupt",
6+
"aoid": "ReturnIfAbrupt"
7+
},
8+
"Get": {
9+
"id": "sec-get-o-p",
10+
"aoid": "Get"
11+
}
612
}
713
}
814
}

spec/index.html

+8-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ <h2>Stylesheet</h2>
3838
<emu-clause id="metadata">
3939
<h1>Metadata</h1>
4040
<p>There are a number of settings that allow customizations or enable generation of boilerplate. Metadata can be included in the document and passed on the command line, for example `--no-toc --title "Document 1"`. Metadata given on the command line takes precedence.</p>
41-
<p>To add metadata to your document, use yaml syntax inside a `<pre class=metadata>` element somewhere in the root of your document.</p>
41+
<p>To add metadata to your document, use yaml syntax inside a `&lt;pre class=metadata>` element somewhere in the root of your document.</p>
4242
<p>The following table lists the currently supported metadata:</p>
4343
<table>
4444
<tr><td>toc</td><td>Emit table of contents. Boolean, default true.</td></tr>
@@ -108,6 +108,13 @@ <h3>Result</h3>
108108
</emu-alg>
109109
</emu-clause>
110110

111+
<emu-clause id="emu-eqn">
112+
<h1>emu-eqn</h1>
113+
<p>An equation, similar to those found in ES6 <emu-xref href="#sec-year-number"></emu-xref>.</p>
114+
115+
<h2>Attributes</h2>
116+
<p><b>aoid:</b> Required: the abstract operation id that this equation defines.</p>
117+
</emu-clause>
111118
<emu-clause id="emu-note">
112119
<h1>emu-note</h1>
113120
<p>Non-normative explanatory text.</p>

test/eqn.html

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<link rel=stylesheet href="./css/elements.css">
2+
<pre class=metadata>toc: false</pre>
3+
<emu-alg>
4+
1. Return Value(_val_);
5+
</emu-alg>
6+
7+
<emu-eqn aoid="Value2">
8+
Value2(t)
9+
= DateValue(t) if Type(t) is string
10+
= t
11+
</emu-eqn>
12+
13+
<emu-eqn aoid="DateValue">
14+
DateValue(t)
15+
= 0 if t = 0
16+
= 1 if t = 1
17+
= 2
18+
</emu-eqn>
19+
20+
<emu-eqn aoid="Value">
21+
Value(t)
22+
= DateValue(t) if Type(t) is string
23+
= t
24+
</emu-eqn>
25+
26+
<emu-alg>
27+
1. Return Value(_val_);
28+
</emu-alg>

test/eqn.html.baseline

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<head><link rel="stylesheet" href="./css/elements.css">
3+
</head><body>
4+
<emu-alg><ol><li>Return <a href="#Value">Value</a>(<var>val</var>);</li></ol></emu-alg>
5+
6+
<emu-eqn aoid="Value2"><div> <a href="#Value2">Value2</a>(t)</div><div> = <a href="#DateValue">DateValue</a>(t) if <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-ecmascript-data-types-and-values">Type</a>(t) is string</div><div> = t</div></emu-eqn>
7+
8+
<emu-eqn aoid="DateValue"><div> <a href="#DateValue">DateValue</a>(t)</div><div> = 0 if t = 0</div><div> = 1 if t = 1</div><div> = 2</div></emu-eqn>
9+
10+
<emu-eqn aoid="Value"><div> <a href="#Value">Value</a>(t)</div><div> = <a href="#DateValue">DateValue</a>(t) if <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-ecmascript-data-types-and-values">Type</a>(t) is string</div><div> = t</div></emu-eqn>
11+
12+
<emu-alg><ol><li>Return <a href="#Value">Value</a>(<var>val</var>);</li></ol></emu-alg>
13+
</body>

0 commit comments

Comments
 (0)