htmlslice
An HTML-aware String#slice.
Getting Started
On the server
Install the module with: npm install htmlslice
var HtmlSlice = HtmlSlice; var h = 'sample <a href="#">link <br/><i>test</i></a> foo<br/>bar';hlength // 25h // 'sample <a href="#">link <br/></a>'h // '<a href="#">ink <br/><i>t</i></a>'h // '<a href="#"><br/><i>test</i></a> foo<br/>'h // '<a href="#"><i>t</i></a> foo<br/>b'
In the browser
Download the production version or the development version.
In your web page:
In your code, you can attach htmlslice's methods to any object.
Documentation
Create a new HtmlSlice(htmlString)
object. The new
is optional. Use its .length
property and .slice(begin [, end])
method like you would a String.
Note: tags must be balanced, and self-closing tags must end in />
.
Examples
You can take a look at the unit tests, or this animated jQuery example.
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.
Also, please don't edit files in the "dist" subdirectory as they are generated via grunt. You'll find source code in the "lib" subdirectory!
Release History
(for some reason, GitHub displays the following list incorrectly unless there is content here)
- 0.1.1 - 2012/02/17 - Fixing minor issue with \n characters.
- 0.1.0 - 2012/02/17 - Initial Release
License
Copyright (c) 2012 "Cowboy" Ben Alman
Licensed under the MIT license.