Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

html-to-text

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-to-text - npm Package Compare versions

Comparing version 2.1.1 to 2.1.2

16

lib/formatter.js

@@ -106,5 +106,10 @@ var _ = require('underscore');

var whiteSpaceRegex = /^\s*$/;
function formatUnorderedList(elem, fn, options) {
var result = '';
_.each(elem.children, function(elem) {
var nonWhiteSpaceChildren = (elem.children || []).filter(function(child) {
return child.type !== 'text' || !whiteSpaceRegex.test(child.raw);
});
_.each(nonWhiteSpaceChildren, function(elem) {
result += formatListItem(' * ', elem, fn, options);

@@ -117,7 +122,10 @@ });

var result = '';
var nonWhiteSpaceChildren = (elem.children || []).filter(function(child) {
return child.type !== 'text' || !whiteSpaceRegex.test(child.raw);
});
// Make sure there are list items present
if (elem.children && elem.children.length) {
if (nonWhiteSpaceChildren.length) {
// Calculate the maximum length to i.
var maxLength = elem.children.length.toString().length;
_.each(elem.children, function(elem, i) {
var maxLength = nonWhiteSpaceChildren.length.toString().length;
_.each(nonWhiteSpaceChildren, function(elem, i) {
var index = i + 1;

@@ -124,0 +132,0 @@ // Calculate the needed spacing for nice indentation.

@@ -41,4 +41,3 @@ var fs = require('fs');

}, {
verbose: true,
ignoreWhitespace: true
verbose: true
});

@@ -45,0 +44,0 @@ new htmlparser.Parser(handler).parseComplete(html);

{
"name": "html-to-text",
"version": "2.1.1",
"version": "2.1.2",
"description": "Advanced html to plain text converter",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -173,2 +173,14 @@ var expect = require('chai').expect;

describe('lists', function() {
it('should handle empty unordered lists', function() {
var testString = '<ul></ul>';
expect(htmlToText.fromString(testString)).to.equal('');
});
it('should handle empty ordered lists', function() {
var testString = '<ol></ol>';
expect(htmlToText.fromString(testString)).to.equal('');
});
});
describe('entities', function () {

@@ -418,3 +430,10 @@ it('does not insert null bytes', function () {

});
})
});
describe('whitespace', function() {
it('should not be ignored inside a whitespace-only node', function() {
var testString = 'foo<span> </span>bar';
expect(htmlToText.fromString(testString)).to.equal('foo bar');
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc