An open API service indexing awesome lists of open source software.

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.

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
---