Skip to content

Commit

Permalink
Version bumped to 4.0.0. package-lock.json added. README updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
Malte Legenhausen committed Mar 7, 2018
1 parent 1a3d878 commit d561095
Show file tree
Hide file tree
Showing 4 changed files with 1,842 additions and 139 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
# Changelog

## Version 4.0.0

* Support dropped for node version < 4.
* New option `unorderedListItemPrefix` added.

## Version 3.3.0

* Ability to pass custom formatting via the `format` option #128
Expand Down
277 changes: 139 additions & 138 deletions README.md
Expand Up @@ -33,10 +33,10 @@ You can read from a file via:
var htmlToText = require('html-to-text');

htmlToText.fromFile(path.join(__dirname, 'test.html'), {
tables: ['#invoice', '.address']
tables: ['#invoice', '.address']
}, (err, text) => {
if (err) return console.error(err);
console.log(text);
if (err) return console.error(err);
console.log(text);
});
```

Expand All @@ -46,7 +46,7 @@ or directly from a string:
var htmlToText = require('html-to-text');

var text = htmlToText.fromString('<h1>Hello World</h1>', {
wordwrap: 130
wordwrap: 130
});
console.log(text);
```
Expand All @@ -72,23 +72,24 @@ You can configure the behaviour of html-to-text with the following options:
* `wrapCharacters` is an array containing the characters that may be wrapped on, these are used in order
* `forceWrapOnLimit` defines whether to break long words on the limit if `true`.
* `format` pass an object to enable custom formatting for specific elements (see below)
* `unorderedListItemPrefix` defines the string that is used as item prefix for unordered lists `<ol>`. Default: `' * '`

### Override formatting for specific elements

By using the `format` option, you can specify formatting for these elements: `text`, `image`, `lineBreak`, `paragraph`, `anchor`, `heading`, `table`, `orderedList`, `unorderedList`, `listItem`, `horizontalLine`.

Each key must be a function which eventually receive `node` (the current node), `fn` (the next formatting function) and `options` (the options passed to html-to-text).
Each key must be a function which eventually receive `elem` (the current elem), `fn` (the next formatting function) and `options` (the options passed to html-to-text).

```js
var htmlToText = require('html-to-text');

var text = htmlToText.fromString('<h1>Hello World</h1>', {
format: {
heading: function (elem, fn, options) {
var h = fn(elem.children, options);
return '====\n' + h.toUpperCase() + '\n====';
}
}
format: {
heading: function (elem, fn, options) {
var h = fn(elem.children, options);
return '====\n' + h.toUpperCase() + '\n====';
}
}
});

console.log(text);
Expand Down Expand Up @@ -116,133 +117,133 @@ The `tables` option has to be declared as comma separated list without whitespac

```html
<html>
<head>
<meta charset="utf-8">
</head>

<body>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<h2>Paragraphs</h2>
<p class="normal-space">At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. <a href="www.github.com">Github</a>
</p>
<p class="normal-space">At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
</p>
</td>
<td></td>
</tr>
<tr>
<td>
<hr/>
<h2>Pretty printed table</h2>
<table id="invoice">
<thead>
<tr>
<th>Article</th>
<th>Price</th>
<th>Taxes</th>
<th>Amount</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>
Product 1<br />
<span style="font-size:0.8em">Contains: 1x Product 1</span>
</p>
</td>
<td align="right" valign="top">6,99&euro;</td>
<td align="right" valign="top">7%</td>
<td align="right" valign="top">1</td>
<td align="right" valign="top">6,99€</td>
</tr>
<tr>
<td>Shipment costs</td>
<td align="right">3,25€</td>
<td align="right">7%</td>
<td align="right">1</td>
<td align="right">3,25€</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="3">to pay: 10,24€</td>
</tr>
<tr>
<td></td>
<td></td>
<td colspan="3">Taxes 7%: 0,72€</td>
</tr>
</tfoot>
</table>

</td>
<td></td>
</tr>
<tr>
<td>
<hr/>
<h2>Lists</h2>
<ul>
<li>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</li>
<li>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</li>
</ul>
<ol>
<li>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</li>
<li>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</li>
</ol>
</td>
</tr>
<tr>
<td>
<hr />
<h2>Column Layout with tables</h2>
<table class="address">
<tr>
<th align="left">Invoice Address</th>
<th align="left">Shipment Address</th>
</tr>
<tr>
<td align="left">
<p>
Mr.<br/>
John Doe<br/>
Featherstone Street 49<br/>
28199 Bremen<br/>
</p>
</td>
<td align="left">
<p>
Mr.<br/>
John Doe<br/>
Featherstone Street 49<br/>
28199 Bremen<br/>
</p>
</td>
</tr>
</table>
</td>
<td></td>
</tr>
<tr>
<td>
<hr/>
<h2>Mailto formating</h2>
<p class="normal-space small">
Some Company<br />
Some Street 42<br />
Somewhere<br />
E-Mail: <a href="mailto:test@example.com">Click here</a>
</p>
</td>
</tr>
</table>
</body>
<head>
<meta charset="utf-8">
</head>

<body>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<h2>Paragraphs</h2>
<p class="normal-space">At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. <a href="www.github.com">Github</a>
</p>
<p class="normal-space">At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
</p>
</td>
<td></td>
</tr>
<tr>
<td>
<hr/>
<h2>Pretty printed table</h2>
<table id="invoice">
<thead>
<tr>
<th>Article</th>
<th>Price</th>
<th>Taxes</th>
<th>Amount</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>
Product 1<br />
<span style="font-size:0.8em">Contains: 1x Product 1</span>
</p>
</td>
<td align="right" valign="top">6,99&euro;</td>
<td align="right" valign="top">7%</td>
<td align="right" valign="top">1</td>
<td align="right" valign="top">6,99€</td>
</tr>
<tr>
<td>Shipment costs</td>
<td align="right">3,25€</td>
<td align="right">7%</td>
<td align="right">1</td>
<td align="right">3,25€</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="3">to pay: 10,24€</td>
</tr>
<tr>
<td></td>
<td></td>
<td colspan="3">Taxes 7%: 0,72€</td>
</tr>
</tfoot>
</table>

</td>
<td></td>
</tr>
<tr>
<td>
<hr/>
<h2>Lists</h2>
<ul>
<li>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</li>
<li>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</li>
</ul>
<ol>
<li>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</li>
<li>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</li>
</ol>
</td>
</tr>
<tr>
<td>
<hr />
<h2>Column Layout with tables</h2>
<table class="address">
<tr>
<th align="left">Invoice Address</th>
<th align="left">Shipment Address</th>
</tr>
<tr>
<td align="left">
<p>
Mr.<br/>
John Doe<br/>
Featherstone Street 49<br/>
28199 Bremen<br/>
</p>
</td>
<td align="left">
<p>
Mr.<br/>
John Doe<br/>
Featherstone Street 49<br/>
28199 Bremen<br/>
</p>
</td>
</tr>
</table>
</td>
<td></td>
</tr>
<tr>
<td>
<hr/>
<h2>Mailto formating</h2>
<p class="normal-space small">
Some Company<br />
Some Street 42<br />
Somewhere<br />
E-Mail: <a href="mailto:test@example.com">Click here</a>
</p>
</td>
</tr>
</table>
</body>
</html>
```

Expand Down

0 comments on commit d561095

Please sign in to comment.