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 0.1.0 to 1.0.0

61

lib/formatter.js

@@ -10,11 +10,25 @@ var _ = require('underscore');

return helper.wordwrap(elem.needsSpace ? ' ' + text : text, options.wordwrap);
};
}
function formatImage(elem, options) {
var result = '';
if (elem.attribs.alt) {
result += elem.attribs.alt;
}
if (elem.attribs.alt && elem.attribs.src) {
result += ' ';
}
if (elem.attribs.src) {
result += '[' + elem.attribs.src + ']';
}
return (result);
}
function formatLineBreak(elem, fn, options) {
return '\n' + fn(elem.children, options);
};
}
function formatParagraph(elem, fn, options) {
return fn(elem.children, options) + '\n\n';
};
}

@@ -34,2 +48,5 @@ function formatHeading(elem, fn, options) {

var result = _s.strip(fn(elem.children || [], options));
if (!result) {
result = '';
}
// Get the href, if present

@@ -39,11 +56,11 @@ if (elem.attribs && elem.attribs.href) {

}
if (result && href) {
if (href) {
result += ' [' + href + ']';
}
return formatText({ raw: result || href, needsSpace: elem.needsSpace }, options);
};
}
function formatHorizontalLine(elem, fn, options) {
return _s.repeat('-', options.wordwrap) + '\n\n';
};
}

@@ -60,3 +77,3 @@ function formatListItem(prefix, elem, fn, options) {

return prefix + text + '\n';
};
}

@@ -69,17 +86,20 @@ function formatUnorderedList(elem, fn, options) {

return result + '\n';
};
}
function formatOrderedList(elem, fn, options) {
var result = '';
// Calculate the maximum length to i.
var maxLength = elem.children.length.toString().length;
_.each(elem.children, function(elem, i) {
var index = i + 1;
// Calculate the needed spacing for nice indentation.
var spacing = maxLength - index.toString().length;
var prefix = ' ' + index + '. ' + _s.repeat(' ', spacing);
result += formatListItem(prefix, elem, fn, options);
});
// Make sure there are list items present
if (elem.children && elem.children.length) {
// Calculate the maximum length to i.
var maxLength = elem.children.length.toString().length;
_.each(elem.children, function(elem, i) {
var index = i + 1;
// Calculate the needed spacing for nice indentation.
var spacing = maxLength - index.toString().length;
var prefix = ' ' + index + '. ' + _s.repeat(' ', spacing);
result += formatListItem(prefix, elem, fn, options);
});
}
return result + '\n';
};
}

@@ -111,3 +131,3 @@ function tableToString(table) {

return text + '\n';
};
}

@@ -148,5 +168,6 @@ function formatTable(elem, fn, options) {

return tableToString(table);
};
}
exports.text = formatText;
exports.image = formatImage;
exports.lineBreak = formatLineBreak;

@@ -153,0 +174,0 @@ exports.paragraph = formatParagraph;

@@ -81,2 +81,5 @@ var fs = require('fs');

switch(elem.name.toLowerCase()) {
case 'img':
result += format.image(elem, options);
break;
case 'a':

@@ -83,0 +86,0 @@ // Inline element needs a leading space if `result` currently

{
"name": "html-to-text",
"version": "0.1.0",
"version": "1.0.0",
"description": "Advanced html to plain text converter",

@@ -40,4 +40,4 @@ "main": "index.js",

],
"engines": {
"node": "~0.8.0"
"engines": {
"node": ">= 0.8.0 <0.12"
},

@@ -44,0 +44,0 @@ "bin": {

Sorry, the diff of this file is not supported yet

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