https://github.com/skx/link_extractor.js
Extract hyperlinks from javascript strings.
https://github.com/skx/link_extractor.js
Last synced: 9 months ago
JSON representation
Extract hyperlinks from javascript strings.
- Host: GitHub
- URL: https://github.com/skx/link_extractor.js
- Owner: skx
- License: other
- Created: 2014-04-11T19:18:16.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-05-12T12:10:59.000Z (over 11 years ago)
- Last Synced: 2025-02-09T16:43:14.992Z (11 months ago)
- Language: JavaScript
- Size: 176 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
link_extractor
--------------
This is a simple `node.js` module for extracting hyperlinks from javascript
strings.
It currently understands three different linking strategies:
* HTML Links.
* `Test`
* BBCode Links.
* `[url=http://example.com/]example[/url]`
* `[link=http://example.com/]example[/link]`
* Links surrounded by [].
* `[http://example.com This is my title]`
Installation
------------
You should be able to install this module by executing:
$ npm install link_extractor
Failing that you can clone the repository, and load the code via:
require( "./link_extractor" );
Examples
--------
//
// Use the node.js assert module to validate our code.
//
var c = require( "link_extractor" );
var assert = require('assert');
//
// Did we find one link from the given string?
//
result = c.extract( '
This is a test ...
' );
assert( result.length == 1 )
//
// Is the single result the correct one?
//
assert(result[0]['text'] == "test",
"The first link has the correct anchor-text" )
assert(result[0]['link'] == "href=\"http://example.com/\"",
"The first link has the correct URL" )
Notes
-----
This code was abstracted from the [blogspam.js](https://github.com/skx/blogspam.js) repository.
License
-------
Please consider this licensed under the two-clause BSD license, included in the
file [LICENSE](LICENSE).
Steve
---