https://github.com/jsantell/node-link-injection
Parse text for keywords and replace with links for documentation
https://github.com/jsantell/node-link-injection
Last synced: 28 days ago
JSON representation
Parse text for keywords and replace with links for documentation
- Host: GitHub
- URL: https://github.com/jsantell/node-link-injection
- Owner: jsantell
- License: mit
- Created: 2012-10-15T04:10:37.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-10-15T23:27:37.000Z (over 12 years ago)
- Last Synced: 2025-03-02T22:08:44.401Z (about 2 months ago)
- Language: JavaScript
- Homepage: https://npmjs.org/package/link-injection
- Size: 106 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
link-injection
======
Parse text for keywords and replace with links for documentation### How it works
`link-injection` parses arbitrary text and replaces all keywords with an anchor link to the keyword's reference. Excellent for creating hyperlinks in documentation to other parts of the documentation and who knows what else. What is supported:
* Can parse plain text, or HTML -- will not create an anchor inside of another anchor
* Full word matching -- if `Array` is a keyword, it will not transpose `Float32Array` into an anchor### Installing
* `npm install link-injection`
### Methods
* `parse( text, map, options )` Parses string `text` replacing instances of `map`'s keys with an anchor with an href to the key's value.
### Options
* `caseSensitive` : Whether or not the keyword match should be case-sensitive. (default: `true`)
### Usage
```javascript
var
inject = require( 'link-inject' ),
html = 'Modern browsers are now implementing a Float32Array type, ' +';
'which is a typed array version of an Array, except it only holds 32-bit ' +
'floating point numbers. The Float32Array is ' +
'frequently used in 3D WebGL applications and audio processing.
// Using local links, but can be anything -- the keys' values are put into the href attribute
map = {
'Array' : '#Array',
'Float32Array' : '#Float32Array'
};var output = inject.parse( html, map );
console.log( output );
```Outputs (spacing added for viewing):
```html
Modern browsers are now implementing a Float32Array
type, which is a typed array version of an Array, except it
only holds 32-bit floating point numbers. The Float32Array
is frequently used in 3D WebGL applications and audio processing.
```Development
---Run `make` in the project root to build the coffee into JavaScript. Run `npm test` from project root -- requires `mocha` to be installed globally