Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/madarche/definition-linker
An NPM package utility to automatically create links to definition URLs
https://github.com/madarche/definition-linker
Last synced: 20 days ago
JSON representation
An NPM package utility to automatically create links to definition URLs
- Host: GitHub
- URL: https://github.com/madarche/definition-linker
- Owner: madarche
- License: mit
- Created: 2017-08-21T17:47:14.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-06T17:25:43.000Z (almost 7 years ago)
- Last Synced: 2024-12-17T03:25:42.239Z (21 days ago)
- Language: JavaScript
- Homepage:
- Size: 30.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Definition linker
=================[![NPM version](http://img.shields.io/npm/v/definition-linker.svg)](https://www.npmjs.org/package/definition-linker)
[![Dependency Status](https://david-dm.org/madarche/definition-linker.svg)](https://david-dm.org/madarche/definition-linker)
[![devDependency Status](https://david-dm.org/madarche/definition-linker/dev-status.svg)](https://david-dm.org/madarche/definition-linker#info=devDependencies)
[![Build Status](https://travis-ci.org/madarche/definition-linker.svg?branch=master)](https://travis-ci.org/madarche/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
```javascript
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.```javascript
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:```javascript
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 logiciel libre', '#node.js');
```Development
-----------It is possible to disable linking on some terms in the HTML by setting a
"nolink" class:```shell
export DEBUG='definition-linker'
npm test
```Contributions
-------------Pull Requests and contributions in general are welcome as long as they follow
the [Node aesthetic].[Node aesthetic]: http://substack.net/node_aesthetic