Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Es6 moar things #1142

Merged
merged 3 commits into from Mar 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitignore
Expand Up @@ -22,19 +22,21 @@ js/core/default-root-attr.js
js/core/dfn.js
js/core/examples.js
js/core/figures.js
js/core/fix-headers.js
js/core/highlight.js
js/core/id-headers.js
js/core/include-config.js
js/core/inlines.js
js/core/markdown.js

js/core/override-configuration.js
js/core/post-process.js
js/core/pre-process.js
js/core/pubsubhub.js
js/core/remove-respec.js
js/core/respec-ready.js
js/core/utils.js
js/core/webidl.js
js/core/webidl-index.js
js/core/webidl.js
js/core/worker.js
js/templates.js
js/w3c/rfc2119.js
24 changes: 0 additions & 24 deletions js/core/fix-headers.js

This file was deleted.

22 changes: 0 additions & 22 deletions js/core/id-headers.js

This file was deleted.

101 changes: 0 additions & 101 deletions js/core/inlines.js

This file was deleted.

16 changes: 16 additions & 0 deletions src/core/fix-headers.js
@@ -0,0 +1,16 @@
// Module core/fix-headers
// Make sure that all h1-h6 headers (that are first direct children of sections) are actually
// numbered at the right depth level. This makes it possible to just use any of them (conventionally
// h2) with the knowledge that the proper depth level will be used

export function run(conf, doc, cb) {
var $secs = $("section:not(.introductory)", doc)
.find("h1:first, h2:first, h3:first, h4:first, h5:first, h6:first");
$secs.each(function() {
var depth = $(this).parents("section").length + 1;
if (depth > 6) depth = 6;
var h = "h" + depth;
if (this.localName.toLowerCase() !== h) $(this).renameElement(h);
});
cb();
}
14 changes: 14 additions & 0 deletions src/core/id-headers.js
@@ -0,0 +1,14 @@
// Module core/id-headers
// All headings are expected to have an ID, unless their immediate container has one.
// This is currently in core though it comes from a W3C rule. It may move in the future.

export function run(conf, doc, cb) {
$("h2, h3, h4, h5, h6").each(function() {
var $h = $(this);
if (!$h.attr("id")) {
if ($h.parent("section").attr("id") && $h.prev().length === 0) return;
$h.makeID();
}
});
cb();
}
95 changes: 95 additions & 0 deletions src/core/inlines.js
@@ -0,0 +1,95 @@
// Module core/inlines
// Process all manners of inline information. These are done together despite it being
// seemingly a better idea to orthogonalise them. The issue is that processing text nodes
// is harder to orthogonalise, and in some browsers can also be particularly slow.
// Things that are recognised are <abbr>/<acronym> which when used once are applied
// throughout the document, [[REFERENCES]]/[[!REFERENCES]], and RFC2119 keywords.
// CONFIGURATION:
// These options do not configure the behaviour of this module per se, rather this module
// manipulates them (oftentimes being the only source to set them) so that other modules
// may rely on them.
// - normativeReferences: a map of normative reference identifiers.
// - informativeReferences: a map of informative reference identifiers.
// - respecRFC2119: a list of the number of times each RFC2119
// key word was used. NOTE: While each member is a counter, at this time
// the counter is not used.
import { pub } from "core/pubsubhub";

export function run(conf, doc, cb) {
doc.normalize();
if (!conf.normativeReferences) conf.normativeReferences = new Set();
if (!conf.informativeReferences) conf.informativeReferences = new Set();
if (!conf.respecRFC2119) conf.respecRFC2119 = {};

// PRE-PROCESSING
var abbrMap = {};
$("abbr[title]", doc).each(function() { abbrMap[$(this).text()] = $(this).attr("title"); });
var aKeys = [];
for (var k in abbrMap) aKeys.push(k);
aKeys.sort(function(a, b) {
if (b.length < a.length) return -1;
if (a.length < b.length) return 1;
return 0;
});
var abbrRx = aKeys.length ? "(?:\\b" + aKeys.join("\\b)|(?:\\b") + "\\b)" : null;

// PROCESSING
var txts = $("body", doc).allTextNodes(["pre"]);
var rx = new RegExp("(\\bMUST(?:\\s+NOT)?\\b|\\bSHOULD(?:\\s+NOT)?\\b|\\bSHALL(?:\\s+NOT)?\\b|" +
"\\bMAY\\b|\\b(?:NOT\\s+)?REQUIRED\\b|\\b(?:NOT\\s+)?RECOMMENDED\\b|\\bOPTIONAL\\b|" +
"(?:\\[\\[(?:!|\\\\)?[A-Za-z0-9\\.-]+\\]\\])" + (abbrRx ? "|" + abbrRx : "") + ")");
for (var i = 0; i < txts.length; i++) {
var txt = txts[i];
var subtxt = txt.data.split(rx);
if (subtxt.length === 1) continue;

var df = doc.createDocumentFragment();
while (subtxt.length) {
var t = subtxt.shift();
var matched = null;
if (subtxt.length) matched = subtxt.shift();
df.appendChild(doc.createTextNode(t));
if (matched) {
// RFC 2119
if (/MUST(?:\s+NOT)?|SHOULD(?:\s+NOT)?|SHALL(?:\s+NOT)?|MAY|(?:NOT\s+)?REQUIRED|(?:NOT\s+)?RECOMMENDED|OPTIONAL/.test(matched)) {
matched = matched.split(/\s+/).join(" ");
df.appendChild($("<em/>").attr({ "class": "rfc2119", title: matched }).text(matched)[0]);
// remember which ones were used
conf.respecRFC2119[matched] = true;
}
// BIBREF
else if (/^\[\[/.test(matched)) {
var ref = matched;
ref = ref.replace(/^\[\[/, "");
ref = ref.replace(/\]\]$/, "");
if (ref.indexOf("\\") === 0) {
df.appendChild(doc.createTextNode("[[" + ref.replace(/^\\/, "") + "]]"));
} else {
var norm = false;
if (ref.indexOf("!") === 0) {
norm = true;
ref = ref.replace(/^!/, "");
}
// contrary to before, we always insert the link
if (norm) conf.normativeReferences.add(ref);
else conf.informativeReferences.add(ref);
df.appendChild(doc.createTextNode("["));
df.appendChild($("<cite/>").wrapInner($("<a/>").attr({ "class": "bibref", href: "#bib-" + ref }).text(ref))[0]);
df.appendChild(doc.createTextNode("]"));
}
}
// ABBR
else if (abbrMap[matched]) {
if ($(txt).parents("abbr").length) df.appendChild(doc.createTextNode(matched));
else df.appendChild($("<abbr/>").attr({ title: abbrMap[matched] }).text(matched)[0]);
}
// FAIL -- not sure that this can really happen
else {
pub("error", "Found token '" + matched + "' but it does not correspond to anything");
}
}
}
txt.parentNode.replaceChild(df, txt);
}
cb();
}