Skip to content

Question: implementing link configuration #24

@isaakengineer

Description

@isaakengineer

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)'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions