html-to-text
Advanced tools
Comparing version 2.1.1 to 2.1.2
@@ -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'); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
69458
907