Comparing version 2.8.1 to 2.8.2
@@ -9,15 +9,5 @@ 'use strict'; | ||
const contents = this.node.innerHTML; | ||
let html = this.autolinkOps(emd.document(contents)); | ||
let html = emd.document(contents); | ||
this.node.innerHTML = html; | ||
} | ||
autolinkOps(contents) { | ||
return contents.replace(/(\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 '<a href="' + op.location + '#' + op.id + '">' + name + '</a>('; | ||
}.bind(this)); | ||
} | ||
}; |
@@ -21,4 +21,4 @@ 'use strict'; | ||
.join('</div><div>'); | ||
this.node.innerHTML = this.autolinkOps(contents); | ||
this.node.innerHTML = contents; | ||
} | ||
}; |
@@ -7,3 +7,4 @@ 'use strict'; | ||
module.exports = class Production extends Builder { | ||
class Production extends Builder { | ||
constructor(spec, node) { | ||
@@ -30,9 +31,12 @@ super(spec, node); | ||
const id = 'prod-' + this.name; | ||
if (!this.spec.biblio.productions[id]) { | ||
this.id = id; | ||
this.primary = true; | ||
this.spec.biblio.productions[this.id] = { id: id, location: '', name: this.name }; | ||
} | ||
this.id = id; | ||
this.primary = !Production.byId[id] || node.hasAttribute('primary') || node.parentNode.hasAttribute('primary'); | ||
if (!this.spec._prodsByName[this.name]) { | ||
if (this.primary) { | ||
if (Production.byId[id]) { | ||
Production.byId[id].primary = false; | ||
} | ||
Production.byId[id] = this; | ||
this.spec.biblio.productions[id] = { id: id, location: '', name: this.name }; | ||
this.spec._prodsByName[this.name] = this; | ||
@@ -103,3 +107,5 @@ } | ||
} | ||
}; | ||
} | ||
Production.byId = {}; | ||
module.exports = Production; |
@@ -28,3 +28,3 @@ 'use strict'; | ||
const NO_CLAUSE_AUTOLINK = ['PRE', 'CODE', 'EMU-CLAUSE', 'EMU-ALG', 'EMU-PRODUCTION', 'EMU-GRAMMAR', 'EMU-XREF', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'EMU-EQN']; | ||
const NO_CLAUSE_AUTOLINK = ['PRE', 'CODE', 'EMU-CLAUSE', 'EMU-PRODUCTION', 'EMU-GRAMMAR', 'EMU-XREF', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'EMU-EQN', 'EMU-ALG']; | ||
const clauseTextNodesUnder = utils.textNodesUnder(NO_CLAUSE_AUTOLINK); | ||
@@ -49,2 +49,3 @@ const NO_ALG_AUTOLINK = ['PRE', 'CODE', 'EMU-XREF']; | ||
this.imports = []; | ||
this.node = this.doc.body; | ||
this._numberer = ClauseNumbers.iterator(); | ||
@@ -377,3 +378,2 @@ this._figureCounts = { | ||
this._log('Autolinking terms and abstract ops...'); | ||
const termlinkmap = {}; | ||
const autolinkmap = {}; | ||
@@ -383,6 +383,5 @@ | ||
autolinkmap[term] = this.externalBiblio.terms[term]; | ||
termlinkmap[term] = this.externalBiblio.terms[term]; | ||
}, this); | ||
Object.keys(this.externalBiblio.ops).filter(noCommonAbstractOps).forEach(function (op) { | ||
Object.keys(this.externalBiblio.ops).forEach(function (op) { | ||
autolinkmap[op] = this.externalBiblio.ops[op]; | ||
@@ -393,6 +392,5 @@ }, this); | ||
autolinkmap[term] = this.biblio.terms[term]; | ||
termlinkmap[term] = this.biblio.terms[term]; | ||
}, this); | ||
Object.keys(this.biblio.ops).filter(noCommonAbstractOps).forEach(function (op) { | ||
Object.keys(this.biblio.ops).forEach(function (op) { | ||
autolinkmap[op] = this.biblio.ops[op]; | ||
@@ -403,16 +401,16 @@ }, this); | ||
.sort(function (a, b) { return b.length - a.length; }) | ||
.map(function (k) { return '\\b' + k + '\\b(?!\\.\\w|%%|\\]\\])'; }) | ||
.map(function (k) { | ||
if (isCommonAbstractOp(k)) { | ||
return '\\b' + k + '\\b(?=\\()'; | ||
} else { | ||
return '\\b' + k + '\\b(?!\\.\\w|%%|\\]\\])'; | ||
} | ||
}) | ||
.join('|'), 'g'); | ||
const algReplacer = new RegExp(Object.keys(termlinkmap) | ||
.sort(function (a, b) { return b.length - a.length; }) | ||
.map(function (k) { return '\\b' + k + '\\b(?!\\.\\w|%%|\\]\\])'; }) | ||
.join('|'), 'g'); | ||
autolinkWalk(clauseReplacer, autolinkmap, this, this); | ||
const algs = this.doc.getElementsByTagName('emu-alg'); | ||
let algs = this.doc.querySelectorAll('emu-alg, emu-eqn'); | ||
for (let i = 0; i < algs.length; i++) { | ||
const alg = algs[i]; | ||
autolink(algReplacer, termlinkmap, this, alg); | ||
autolink(clauseReplacer, autolinkmap, this, algs[i], this.node.id, true); | ||
} | ||
@@ -423,2 +421,3 @@ } | ||
const types = ['clause', 'production', 'example', 'note', 'figure', 'table']; | ||
for (let i = 0; i < types.length; i++) { | ||
@@ -479,4 +478,4 @@ const type = types[i]; | ||
function autolinkWalk(replacer, autolinkmap, spec, rootClause) { | ||
autolink(replacer, autolinkmap, spec, rootClause.node, rootClause.id); | ||
rootClause.subclauses.forEach(function (subclause) { | ||
autolink(replacer, autolinkmap, spec, subclause.node, subclause.id); | ||
autolinkWalk(replacer, autolinkmap, spec, subclause); | ||
@@ -486,3 +485,3 @@ }); | ||
function autolink(replacer, autolinkmap, spec, node, parentId) { | ||
function autolink(replacer, autolinkmap, spec, node, parentId, allowSameId) { | ||
const textNodes = clauseTextNodesUnder(node); | ||
@@ -497,3 +496,3 @@ | ||
const entry = autolinkmap[match]; | ||
if (!entry || entry.id === parentId) { | ||
if ((!entry || entry.id === parentId) && !allowSameId) { | ||
return match; | ||
@@ -516,4 +515,4 @@ } | ||
function noCommonAbstractOps(op) { | ||
return op !== 'Call' && op !== 'Set' && op !== 'Type' && op !== 'UTC'; | ||
function isCommonAbstractOp(op) { | ||
return op === 'Call' || op === 'Set' || op === 'Type' || op === 'UTC'; | ||
} | ||
@@ -520,0 +519,0 @@ |
{ | ||
"name": "ecmarkup", | ||
"version": "2.8.1", | ||
"version": "2.8.2", | ||
"description": "Custom element definitions and core utilities for markup that specifies ECMAScript and related technologies.", | ||
@@ -5,0 +5,0 @@ "main": "lib/ecmarkup.js", |
@@ -5,2 +5,3 @@ { | ||
"Biblio": { | ||
"aoid": "Biblio", | ||
"id": "sec-biblio" | ||
@@ -7,0 +8,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
481110
89
2215