Skip to content

Commit

Permalink
Merge pull request #36 from w3c/autolink-fix
Browse files Browse the repository at this point in the history
add autolinking as a preprocessor
  • Loading branch information
hayatoito committed Mar 3, 2015
2 parents 2a3b7ed + 1bee5b3 commit 425171c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
13 changes: 3 additions & 10 deletions assets/scripts/autolink.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
(function() {

function getTitle(e) {
var title = e.getAttribute("title") || e.innerText;
return title.toLowerCase().replace(/^\s+/, "").replace(/\s+$/, "").split(/\s+/).join(" ");
};

function resolveAutolink() {
if (!autolinkConfig)
Expand All @@ -22,14 +16,13 @@ function resolveAutolink() {
Array.prototype.slice.call(document.querySelectorAll("a:not([href])")).forEach(function (e) {
if (e.classList.contains("internalDFN"))
return;
var title = getTitle(e);
var title = e.getAttribute("title") || e.textContent;
if (!title) return;
title = title.toLowerCase().replace(/^\s+/, "").replace(/\s+$/, "").split(/\s+/).join(" ");
if (definitionMap[title]) {
e.setAttribute("href", definitionMap[title]);
e.classList.add("externalDFN");
}
});
}

document.addEventListener('DOMContentLoaded', resolveAutolink);

}());
1 change: 1 addition & 0 deletions spec/shadow/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
href: "https://github.com/w3c/webcomponents/commits/gh-pages/spec/shadow/"
}
],
preProcess: [resolveAutolink],
localBiblio: {
"SELECTORS4": {
title: "Selectors Level 4",
Expand Down

0 comments on commit 425171c

Please sign in to comment.