From bcf387a3a75d1d18176c5aded977c78ef9aa4c60 Mon Sep 17 00:00:00 2001 From: Brian Terlson Date: Tue, 18 Aug 2015 17:06:27 -0700 Subject: [PATCH] Add emu-eqn --- css/elements.css | 9 +++++++++ lib/Algorithm.js | 9 +++++---- lib/Eqn.js | 22 ++++++++++++++++++++++ lib/Production.js | 2 +- lib/Spec.js | 23 +++++++++++++++-------- lib/utils.js | 2 +- package.json | 2 +- spec/biblio.json | 12 +++++++++--- spec/index.html | 9 ++++++++- test/eqn.html | 28 ++++++++++++++++++++++++++++ test/eqn.html.baseline | 13 +++++++++++++ 11 files changed, 112 insertions(+), 19 deletions(-) create mode 100644 lib/Eqn.js create mode 100644 test/eqn.html create mode 100644 test/eqn.html.baseline diff --git a/css/elements.css b/css/elements.css index 1aaba131..6ed12734 100644 --- a/css/elements.css +++ b/css/elements.css @@ -72,6 +72,15 @@ emu-alg ol ol ol, ol ol ol ol ol ol { list-style-type: lower-roman; } +emu-eqn { + display: block; + margin-left: 4em; +} + +emu-eqn div:first-child { + margin-left: -2em; +} + emu-note { display: block; margin-left: 5em; diff --git a/lib/Algorithm.js b/lib/Algorithm.js index 883a4d65..95f4d01d 100644 --- a/lib/Algorithm.js +++ b/lib/Algorithm.js @@ -6,16 +6,17 @@ const emd = require('ecmarkdown'); module.exports = class Algorithm extends Builder { build() { const contents = this.node.innerHTML; - let html = emd.document(contents); + let html = this.autolinkOps(emd.document(contents)); + this.node.innerHTML = html; + } - html = html.replace(/([A-Z]\w+)\(/g, function (match, name) { + autolinkOps(contents) { + return contents.replace(/([A-Z]\w+)\(/g, function (match, name) { let op = this.spec.biblio.ops[name]; if (!op) op = this.spec.externalBiblio.ops[name]; if (!op) return match; return '' + name + '('; }.bind(this)); - - this.node.innerHTML = html; } }; diff --git a/lib/Eqn.js b/lib/Eqn.js new file mode 100644 index 00000000..a768232a --- /dev/null +++ b/lib/Eqn.js @@ -0,0 +1,22 @@ +'use strict'; +const Algorithm = require('./Algorithm'); +module.exports = class Eqn extends Algorithm { + constructor(spec, node) { + super(spec, node); + this.aoid = node.getAttribute('aoid'); + this.id = this.aoid; + this.spec.biblio.ops[this.aoid] = { + aoid: this.aoid, + id: this.id, + location: '', + }; + } + + build() { + let contents = this.node.innerHTML; + contents = '
' + contents.split(/\r?\n/g) + .filter(function(s) { return s.trim().length > 0; }) + .join('
'); + this.node.innerHTML = this.autolinkOps(contents); + } +}; diff --git a/lib/Production.js b/lib/Production.js index d06164a7..91e0f302 100644 --- a/lib/Production.js +++ b/lib/Production.js @@ -18,7 +18,7 @@ module.exports = class Production extends Builder { this.rhsesById = {}; const rhses = this.node.querySelectorAll('emu-rhs'); - for (const i = 0; i < rhses.length; i++) { + for (let i = 0; i < rhses.length; i++) { const rhs = new RHS(this.spec, this, rhses[i]); this.rhses.push(rhs); diff --git a/lib/Spec.js b/lib/Spec.js index abc1e7e2..25a6543b 100644 --- a/lib/Spec.js +++ b/lib/Spec.js @@ -17,6 +17,7 @@ const Production = require('./Production'); const ProdRef = require('./ProdRef'); const Grammar = require('./Grammar'); const Xref = require('./Xref'); +const Eqn = require('./Eqn'); const NO_CLAUSE_AUTOLINK = ['PRE', 'CODE', 'EMU-CLAUSE', 'EMU-ALG', 'EMU-PRODUCTION', 'EMU-GRAMMAR', 'EMU-XREF', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6']; const clauseTextNodesUnder = utils.textNodesUnder(NO_CLAUSE_AUTOLINK); @@ -67,16 +68,21 @@ module.exports = class Spec { elems = selector; } + const builders = []; const ps = []; + for (let i = 0; i < elems.length; i++) { + const b = new Builder(this, elems[i]); + builders.push(b); + } + if (opts.buildArgs) { - for (const i = 0; i < elems.length; i++) { - const b = new Builder(this, elems[i]); - ps.push(b.build.apply(b, opts.buildArgs)); + for (let i = 0; i < elems.length; i++) { + ps.push(builders[i].build.apply(builders[i], opts.buildArgs)); } } else { - for (const i = 0; i < elems.length; i++) { - ps.push(new Builder(this, elems[i]).build()); + for (let i = 0; i < elems.length; i++) { + ps.push(builders[i].build()); } } @@ -89,6 +95,7 @@ module.exports = class Spec { .then(this.loadBiblios.bind(this)) .then(this.buildAll.bind(this, 'emu-clause, emu-intro, emu-annex', Clause)) .then(this.buildAll.bind(this, 'emu-grammar', Grammar)) + .then(this.buildAll.bind(this, 'emu-eqn', Eqn)) .then(this.buildAll.bind(this, 'emu-alg', Algorithm)) .then(this.buildAll.bind(this, 'emu-production', Production)) .then(this.buildAll.bind(this, 'emu-prodref', ProdRef)) @@ -177,7 +184,7 @@ module.exports = class Spec { highlightCode() { this._log('Highlighting syntax...'); const codes = this.doc.querySelectorAll('pre code'); - for (const i = 0; i < codes.length; i++) { + for (let i = 0; i < codes.length; i++) { hljs.highlightBlock(codes[i]); } } @@ -214,7 +221,7 @@ module.exports = class Spec { autolinkWalk(clauseReplacer, autolinkmap, this, this); const algs = this.doc.getElementsByTagName('emu-alg'); - for (const i = 0; i < algs.length; i++) { + for (let i = 0; i < algs.length; i++) { const alg = algs[i]; autolink(algReplacer, termlinkmap, this, alg); } @@ -248,7 +255,7 @@ function autolinkWalk(replacer, autolinkmap, spec, rootClause) { function autolink(replacer, autolinkmap, spec, node, parentId) { const textNodes = clauseTextNodesUnder(node); - for (const i = 0; i < textNodes.length; i++) { + for (let i = 0; i < textNodes.length; i++) { const node = textNodes[i]; const template = spec.doc.createElement('template'); diff --git a/lib/utils.js b/lib/utils.js index 867712e2..76b4ad78 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -16,7 +16,7 @@ exports.domWalk = function (root, cb) { const childNodes = root.childNodes; const childLen = childNodes.length; - for (const i = 0; i < childLen; i++) { + for (let i = 0; i < childLen; i++) { const node = childNodes[i]; if (node.nodeType !== 1) continue; diff --git a/package.json b/package.json index e95460b9..f7c91fcd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ecmarkup", - "version": "2.0.0-beta1", + "version": "2.0.0-beta2", "description": "Custom element definitions and core utilities for markup that specifies ECMAScript and related technologies.", "main": "lib/ecmarkup.js", "scripts": { diff --git a/spec/biblio.json b/spec/biblio.json index 5579632a..409f7129 100644 --- a/spec/biblio.json +++ b/spec/biblio.json @@ -1,8 +1,14 @@ { "http://people.mozilla.org/~jorendorff/es6-draft.html": { - "abstract operations": { - "ReturnIfAbrupt": "#sec-returnifabrupt", - "Get": "#sec-get-o-p" + "ops": { + "ReturnIfAbrupt": { + "id": "sec-returnifabrupt", + "aoid": "ReturnIfAbrupt" + }, + "Get": { + "id": "sec-get-o-p", + "aoid": "Get" + } } } } diff --git a/spec/index.html b/spec/index.html index 65aebbea..d79b4e2b 100644 --- a/spec/index.html +++ b/spec/index.html @@ -38,7 +38,7 @@

Stylesheet

Metadata

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.

-

To add metadata to your document, use yaml syntax inside a `