trimHtml

by brankosekulic

brankosekulic / trimHtml
210 Stars 22 Forks Last release: Not found 42 Commits 7 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

trim-html

Cutting a HTML String without breaking HTML Tags

Build Status

Installation

Node.js

npm package

js
    npm install trim-html

use in node.js

js
    var trimHtml = require('trim-html');

Usage

node.js

    var trimmed = trimHtml(html);

Options

limit

Char limit (default 100)

wordBreak

Break text on half of word (default false)

preserveTags

Maintain HTML tags (default true)

suffix

string that will be appended at the end

moreLink

link to access full content

example:

js
var html = `

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

`;
js
var trim = trimHtml(html, { limit: 200 });
js
// returns object
{
   html: `

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut...

`, more: true // indicates if limit is reached }

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.