definition-linker
v1.1.0
Published
Definition linker is a utility to automatically create links to definition URLs, in a given block of text/HTML
Downloads
3
Maintainers
Readme
Definition linker
Utility to automatically create links to definition URLs, in a given block of text/HTML.
A stemmer method must be provided to match the words given block of text/HTML with the configured definition words.
Usage
Basic
const natural = require('natural');
const definition_linker = require('definition-linker')({
stem: function stem(text) {
// keepStops=true
return natural.PorterStemmerFr.tokenizeAndStem(text, true).join(' ');
}
});
definition_linker.createIndex();
definition_linker.addToIndex('node.js', '#node.js');
definition_linker.addToIndex('logiciel libre', '#logiciel-libre');
// etc.
const html = definition_linker.addLinksInHtml('Node.js est un logiciel libre');
Advanced
addLinksInHtml
and addLinksInText
accept an optional parameter to exclude
linking to a specific definition.
const natural = require('natural');
const definition_linker = require('definition-linker')({
stem: function stem(text) {
// keepStops=true
return natural.PorterStemmerFr.tokenizeAndStem(text, true).join(' ');
}
});
definition_linker.createIndex();
definition_linker.addToIndex('node.js', '#node.js');
definition_linker.addToIndex('logiciel libre', '#logiciel-libre');
// etc.
const html1 = definition_linker.addLinksInHtml('Node.js est un logiciel libre', '#node.js');
const html2 = definition_linker.addLinksInHtml('Il existe de nombreux logiciels libres dont Node.js', '#logiciel-libre');
Nolink
It is possible to disable linking on some terms in the HTML by setting a "nolink" class:
const natural = require('natural');
const definition_linker = require('definition-linker')({
stem: function stem(text) {
// keepStops=true
return natural.PorterStemmerFr.tokenizeAndStem(text, true).join(' ');
}
});
definition_linker.createIndex();
definition_linker.addToIndex('node.js', '#node.js');
definition_linker.addToIndex('logiciel libre, '#logiciel-libre');
// etc.
const html3 = definition_linker.addLinksInHtml('Node.js est un <span class="nolink">logiciel libre</span>', '#node.js');
Development
It is possible to disable linking on some terms in the HTML by setting a "nolink" class:
export DEBUG='definition-linker'
npm test
Contributions
Pull Requests and contributions in general are welcome as long as they follow the Node aesthetic.