Skip to content

Commit

Permalink
Merge branch 'develop' into gh-pages
Browse files Browse the repository at this point in the history
* develop:
  v13.1.0
  fix(core/headers): SoTD doesn't respect sections
  style(core/data-cite-spec): remove forgotten console.log
  feat(core/data-cite): parent can define cite root (closes #684)
  chore(deps/highlight): updates copyright
  • Loading branch information
marcoscaceres committed Jun 5, 2017
2 parents 08435fa + 684eccf commit 250c8f8
Show file tree
Hide file tree
Showing 11 changed files with 391 additions and 216 deletions.
2 changes: 1 addition & 1 deletion builds/respec-w3c-common.build.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion builds/respec-w3c-common.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/deps/highlight.js
@@ -1,4 +1,4 @@
/*! highlight.js v9.11.0 | BSD3 License | git.io/hljslicense */
/*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */
(function(factory) {

// Find the global object for export to both the browser and web workers.
Expand Down
62 changes: 31 additions & 31 deletions js/w3c/templates/cgbg-sotd.html
@@ -1,32 +1,32 @@
<section id='sotd' class='introductory'><h2>{{l10n.sotd}}</h2>
<p>
This specification was published by the <a href='{{wgURI}}'>{{wg}}</a>.
It is not a W3C Standard nor is it on the W3C Standards Track.
{{#if isCGFinal}}
Please note that under the
<a href="https://www.w3.org/community/about/agreements/final/">W3C Community Final Specification Agreement (FSA)</a>
other conditions apply.
{{else}}
Please note that under the
<a href="https://www.w3.org/community/about/agreements/cla/">W3C Community Contributor License Agreement (CLA)</a>
there is a limited opt-out and other conditions apply.
{{/if}}
Learn more about
<a href="https://www.w3.org/community/">W3C Community and Business Groups</a>.
</p>
{{#unless sotdAfterWGinfo}}
{{{sotdCustomParagraph}}}
{{/unless}}
{{#if wgPublicList}}
<p>If you wish to make comments regarding this document, please send them to
<a href='mailto:{{wgPublicList}}@w3.org{{#if subjectPrefix}}?subject={{subjectPrefixEnc}}{{/if}}'>{{wgPublicList}}@w3.org</a>
(<a href='mailto:{{wgPublicList}}-request@w3.org?subject=subscribe'>subscribe</a>,
<a
href='https://lists.w3.org/Archives/Public/{{wgPublicList}}/'>archives</a>){{#if subjectPrefix}}
with <code>{{subjectPrefix}}</code> at the start of your
email's subject{{/if}}.</p>
{{/if}}
{{#if sotdAfterWGinfo}}
{{{sotdCustomParagraph}}}
<h2>{{l10n.sotd}}</h2>
<p>
This specification was published by the <a href='{{wgURI}}'>{{wg}}</a>.
It is not a W3C Standard nor is it on the W3C Standards Track.
{{#if isCGFinal}}
Please note that under the
<a href="https://www.w3.org/community/about/agreements/final/">W3C Community Final Specification Agreement (FSA)</a>
other conditions apply.
{{else}}
Please note that under the
<a href="https://www.w3.org/community/about/agreements/cla/">W3C Community Contributor License Agreement (CLA)</a>
there is a limited opt-out and other conditions apply.
{{/if}}
</section>
Learn more about
<a href="https://www.w3.org/community/">W3C Community and Business Groups</a>.
</p>
{{#unless sotdAfterWGinfo}}
{{{additionalContent}}}
{{/unless}}
{{#if wgPublicList}}
<p>If you wish to make comments regarding this document, please send them to
<a href='mailto:{{wgPublicList}}@w3.org{{#if subjectPrefix}}?subject={{subjectPrefixEnc}}{{/if}}'>{{wgPublicList}}@w3.org</a>
(<a href='mailto:{{wgPublicList}}-request@w3.org?subject=subscribe'>subscribe</a>,
<a
href='https://lists.w3.org/Archives/Public/{{wgPublicList}}/'>archives</a>){{#if subjectPrefix}}
with <code>{{subjectPrefix}}</code> at the start of your
email's subject{{/if}}.</p>
{{/if}}
{{#if sotdAfterWGinfo}}
{{{additionalContent}}}
{{/if}}
{{{additionalSections}}}
301 changes: 150 additions & 151 deletions js/w3c/templates/sotd.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "respec",
"version": "13.0.0",
"version": "13.1.0",
"license": "W3C",
"description": "A technical specification pre-processor.",
"engines": {
Expand Down
18 changes: 12 additions & 6 deletions src/core/data-cite.js
Expand Up @@ -74,9 +74,16 @@ function citeDetailsConverter(conf) {
const isNormative = key.startsWith("!");
const fragPosition = key.search("#");
// The key is a fragment, resolve using the shortName as key
if (key.startsWith("#") && !frag && conf.shortName) {
elem.dataset.cite = conf.shortName;
elem.dataset.citeFrag = key;
if (key.startsWith("#") && !frag) {
// Closes data-cite not starting with "#"
const closest = elem.parentElement.closest(
`[data-cite]:not([data-cite^="#"])`
);
const { key: parentKey, isNormative: closestIsNormative } = closest
? toCiteDetails(closest)
: { key: conf.shortName || "", isNormative: false };
elem.dataset.cite = closestIsNormative ? `!${parentKey}` : parentKey;
elem.dataset.citeFrag = key; // the key is acting as fragment
return toCiteDetails(elem);
}
if (fragPosition !== -1) {
Expand All @@ -93,9 +100,9 @@ function citeDetailsConverter(conf) {
};
}

export function run(conf, doc, cb) {
export async function run(conf) {
const toCiteDetails = citeDetailsConverter(conf);
Array.from(doc.querySelectorAll(["dfn[data-cite], a[data-cite]"]))
Array.from(document.querySelectorAll(["dfn[data-cite], a[data-cite]"]))
.filter(el => el.dataset.cite)
.map(toCiteDetails)
.reduce((conf, { isNormative, key }) => {
Expand All @@ -106,7 +113,6 @@ export function run(conf, doc, cb) {
}
return conf;
}, conf);
cb();
}

export async function linkInlineCitations(doc) {
Expand Down
8 changes: 5 additions & 3 deletions src/core/structure.js
Expand Up @@ -101,9 +101,11 @@ export function run(conf, doc, cb) {
if ("maxTocLevel" in conf === false) {
conf.maxTocLevel = 0;
}
var $secs = $("section:not(.introductory)", doc).find(
"h1:first, h2:first, h3:first, h4:first, h5:first, h6:first"
);
var $secs = $("section:not(.introductory)", doc)
.find("h1:first, h2:first, h3:first, h4:first, h5:first, h6:first")
.toArray()
.filter(elem => elem.closest("section.introductory") === null);
$secs = $($secs);
if (!$secs.length) {
return cb();
}
Expand Down
58 changes: 38 additions & 20 deletions src/w3c/headers.js
Expand Up @@ -104,9 +104,7 @@ import { pub } from "core/pubsubhub";
import tmpls from "templates";

const cgbgHeadersTmpl = tmpls["cgbg-headers.html"];
const cgbgSotdTmpl = tmpls["cgbg-sotd.html"];
const headersTmpl = tmpls["headers.html"];
const sotdTmpl = tmpls["sotd.html"];

hb.registerHelper("showPeople", function(name, items) {
// stuff to handle RDFa
Expand Down Expand Up @@ -609,14 +607,16 @@ export function run(conf, doc, cb) {
$("body", doc).prepend($(bp)).addClass("h-entry");

// handle SotD
var $sotd = $("#sotd");
if ((conf.isCGBG || !conf.isNoTrack || conf.isTagFinding) && !$sotd.length)
var sotd =
document.body.querySelector("#sotd") || document.createElement("section");
if ((conf.isCGBG || !conf.isNoTrack || conf.isTagFinding) && !sotd.id) {
pub(
"error",
"A custom SotD paragraph is required for your type of document."
);
conf.sotdCustomParagraph = $sotd.html();
$sotd.remove();
}
sotd.id = sotd.id || "stod";
sotd.classList.add("introductory");
// NOTE:
// When arrays, wg and wgURI have to be the same length (and in the same order).
// Technically wgURI could be longer but the rest is ignored.
Expand All @@ -627,17 +627,14 @@ export function run(conf, doc, cb) {
// can be shorter — but it still needs to be an array.
var wgPotentialArray = [conf.wg, conf.wgURI, conf.wgPatentURI];
if (
wgPotentialArray.some(function(it) {
return $.isArray(it);
}) &&
wgPotentialArray.some(function(it) {
return !$.isArray(it);
})
)
wgPotentialArray.some(item => Array.isArray(item)) &&
wgPotentialArray.every(item => Array.isArray(item))
) {
pub(
"error",
"If one of 'wg', 'wgURI', or 'wgPatentURI' is an array, they all have to be."
);
}
if ($.isArray(conf.wg)) {
conf.multipleWGs = conf.wg.length > 1;
conf.wgHTML = joinAnd(conf.wg, function(wg, idx) {
Expand Down Expand Up @@ -686,23 +683,44 @@ export function run(conf, doc, cb) {
// ensure subjectPrefix is encoded before using template
if (conf.subjectPrefix !== "")
conf.subjectPrefixEnc = encodeURIComponent(conf.subjectPrefix);
var sotd;
if (conf.isCGBG) sotd = cgbgSotdTmpl(conf);
else sotd = sotdTmpl(conf);
if (sotd) $(sotd).insertAfter($("#abstract"));

sotd.innerHTML = populateSoTD(conf, sotd);

if (!conf.implementationReportURI && (conf.isCR || conf.isPR || conf.isRec)) {
pub(
"error",
"CR, PR, and REC documents need to have an implementationReportURI defined."
);
}
if (conf.isTagFinding && !conf.sotdCustomParagraph) {
if (conf.isTagFinding && !conf.additionalContent) {
pub(
"error",
"warn",
"ReSpec does not support automated SotD generation for TAG findings, " +
"please specify one using a <code><section></code> element with ID=sotd."
"please add the prerequisite content in the 'sotd' section"
);
}
cb();
}

function populateSoTD(conf, sotd) {
const sotdClone = sotd.cloneNode(true);
const additionalNodes = document.createDocumentFragment();
const additionalContent = document.createElement("temp");
// we collect everything until we hit a section,
// that becomes the custom content.
while (sotdClone.hasChildNodes()) {
if (
sotdClone.firstChild.nodeType !== Node.ELEMENT_NODE ||
sotdClone.firstChild.localName !== "section"
) {
additionalNodes.appendChild(sotdClone.firstChild);
continue;
}
break;
}
additionalContent.appendChild(additionalNodes);
conf.additionalContent = additionalContent.innerHTML;
// Whatever sections are left, we throw at the end.
conf.additionalSections = sotdClone.innerHTML;
return tmpls[conf.isCGBG ? "cgbg-sotd.html" : "sotd.html"](conf);
}
71 changes: 70 additions & 1 deletion tests/spec/core/data-cite-spec.js
Expand Up @@ -4,7 +4,51 @@ describe("Core — data-cite attribute", () => {
flushIframes();
done();
});
it(`treats data-cite="#foo" as self citing`, done => {
it(`walks up the tree to find the right reference to cite`, done => {
const ops = {
config: makeBasicConfig(),
body:
makeDefaultBody() +
`
<section data-cite="dahut">
<h2>test</h2>
<p>
<a id="t1" data-cite="#test">a</a>
<dfn id="t2" data-cite="#test">a</dfn>
</p>
<p data-cite="URL">
<a id="t3" data-cite="#urlspec">a</a>
</p>
<section data-cite="URL">
<div data-cite="#fail">
<p data-cite="#fail">
<a id="t4" data-cite="#urlspec">a</a>
<a id="t5" data-cite="CONSOLE#test5">a</a>
</p>
</div>
</section>
</section>
`,
};
ops.config.shortName = "fail";
makeRSDoc(ops).then(doc => {
const t1 = doc.getElementById("t1");
const t2 = doc.getElementById("t2").querySelector("a");
const t3 = doc.getElementById("t3");
const t4 = doc.getElementById("t4");
const t5 = doc.getElementById("t5");
const location = new URL("#test", "http://berjon.com/").href;
expect(t1.href).toEqual(location);
expect(t2.href).toEqual(location);
const urlSpecHref = new URL("#urlspec", "https://url.spec.whatwg.org/").href;
expect(t3.href).toEqual(urlSpecHref);
expect(t4.href).toEqual(urlSpecHref);
const fooBarHref = new URL("#test5", "https://console.spec.whatwg.org/").href;
expect(t5.href).toEqual(fooBarHref);
done();
});
});
it(`treats data-cite="#foo" as self citing when there is no parent data-cite`, done => {
const ops = {
config: makeBasicConfig(),
body:
Expand All @@ -29,6 +73,31 @@ describe("Core — data-cite attribute", () => {
done();
});
});
it("links data-cite attributes as normative/informative reference when parent is citing", done => {
const ops = {
config: makeBasicConfig(),
body:
makeDefaultBody() +
`
<section data-cite="FETCH">
<p><a data-cite="#fetch-thing">informative reference</a></p>
</section>
<section data-cite="!URL">
<p><a data-cite="#url-thing">normative reference</a></p>
</section>
`,
};
makeRSDoc(ops)
.then(doc => {
expect(
doc.querySelector("#bib-URL").closest("section").id
).toEqual("normative-references");
expect(
doc.querySelector("#bib-FETCH").closest("section").id
).toEqual("informative-references");
})
.then(done);
});
it("links directly to externally defined references", done => {
const ops = {
config: makeBasicConfig(),
Expand Down

0 comments on commit 250c8f8

Please sign in to comment.