-
Notifications
You must be signed in to change notification settings - Fork 48
Open
Labels
Description
Thanks for the library, it's really helpful, one question though, and sorry that it's a beginner thing in JS, but how do you implement the link property correctly. Here is how my test looks like:
var contentsSM,
newHeading,
contentsMD;
contentsSM = window.Contents({
articles: document.querySelectorAll('article h2, article h2'),
link : function (guide, article) {
var guideLink,
articleName,
articleId;
guide = $(guide);
article = $(article);
guideLink = $('<a>');
articleName = article.text();
articleId = 'etc';
guideLink
.text(articleName)
.attr('href', '#' + 'etc')
.prependTo(guide);
article
.attr('id', 'etc');
}
});
document.querySelector('#table-of-content').appendChild(contentsSM.list());
Actually what I'm trying to achieve is to have <a href="#1"> and <a href="#2"> and etc, but however I tried to manipulate the articleId, it doesn't work, even something like this:
contentsSM = window.Contents({
articles: document.querySelectorAll('article h2, article h2'),
});
contentsSM.articleId = function(articleName, element) {
return 'how are you';
};
generates:
<h2 id="But can why-questions ever get answered?"><a href="#But can why-questions ever get answered?">But can <em>why-questions </em>ever get answered?</a></h2>
Thanks in advance ...
PS. I setup the contents by npm and require it with window.contents = require('contents)'.