diff --git a/types/email-templates/index.d.ts b/types/email-templates/index.d.ts
index 2d3ac19804..5634e6b1e1 100644
--- a/types/email-templates/index.d.ts
+++ b/types/email-templates/index.d.ts
@@ -10,8 +10,8 @@
// TypeScript Version: 3.3
///
-///
+import { HtmlToTextOptions } from 'html-to-text';
import JSONTransport = require('nodemailer/lib/json-transport');
import Mail = require('nodemailer/lib/mailer');
import SendmailTransport = require('nodemailer/lib/sendmail-transport');
diff --git a/types/html-to-text/html-to-text-tests.ts b/types/html-to-text/html-to-text-tests.ts
index 50c3f43dab..39ccf97358 100644
--- a/types/html-to-text/html-to-text-tests.ts
+++ b/types/html-to-text/html-to-text-tests.ts
@@ -1,29 +1,24 @@
+import { fromString, HtmlToTextOptions } from 'html-to-text';
+import * as formatters from 'html-to-text/lib/formatter';
-
-import * as htmlToText from 'html-to-text';
-
-let htmlOptions: HtmlToTextOptions = {
+const htmlOptions: HtmlToTextOptions = {
wordwrap: null,
tables: true,
hideLinkHrefIfSameAsText: true,
- ignoreImage: true
+ ignoreImage: true,
+ format: {
+ text: (el, options) => {
+ return formatters.text(el, options);
+ },
+ table: (el, walk, options) => {
+ return formatters.table(el, walk, options);
+ },
+ },
};
+const htmlString = '
bold
italic
';
+console.log('Processing string with default options');
+console.log(fromString(htmlString));
-function callback(err: string, result: string) {
- console.log(`callback called with result ${result}`);
-}
-
-console.log("Processing file with default options");
-htmlToText.fromFile("h2t-test.html", callback);
-
-console.log("Processing file with custom options");
-htmlToText.fromFile("h2t-test.html", htmlOptions, callback);
-
-let htmlString = "bold
italic
";
-console.log("Processing string with default options");
-console.log(htmlToText.fromString(htmlString));
-
-console.log("Processing string with custom options");
-console.log(htmlToText.fromString(htmlString, htmlOptions));
-
+console.log('Processing string with custom options');
+console.log(fromString(htmlString, htmlOptions));
diff --git a/types/html-to-text/index.d.ts b/types/html-to-text/index.d.ts
index 8f911df91d..527ad1c8bc 100644
--- a/types/html-to-text/index.d.ts
+++ b/types/html-to-text/index.d.ts
@@ -1,40 +1,20 @@
-// Type definitions for html-to-text v1.4.0
+// Type definitions for html-to-text 5.1
// Project: https://github.com/werk85/node-html-to-text
// Definitions by: Eryk Warren
+// Carson Full
// Definitions: https://github.com/DefinitelyTyped/html-to-text
-interface HtmlToTextStatic {
- /**
- * Convert html content of file to text
- *
- * @param file String with the path of the html file to convert
- * @param options Hash of options
- * @param callback Function with signature function(err, result) called when the conversion is completed
- *
- */
- fromFile(file: string, options: HtmlToTextOptions, callback: Function): void;
-
- /**
- * Convert html content of file to text with the default options.
- *
- * @param file String with the path of the html file to convert
- * @param callback Function with signature function(err, result) called when the conversion is completed
- *
- */
- fromFile(file: string, callback: Function): void;
-
- /**
- * Convert html string to text
- *
- * @param file String with the path of the html file to convert
- * @param options Hash of options
- *
- * @return String with the converted text.
- */
- fromString(str: string, options?: HtmlToTextOptions): string;
-}
+/**
+ * Convert html string to text
+ *
+ * @param str String of html content
+ * @param options Hash of options
+ *
+ * @return String with the converted text.
+ */
+export function fromString(str: string, options?: HtmlToTextOptions): string;
-interface HtmlToTextOptions {
+export interface HtmlToTextOptions {
/**
* Defines after how many chars a line break should follow in p elements.
* Set to null or false to disable word-wrapping. Default: 80
@@ -46,9 +26,9 @@ interface HtmlToTextOptions {
* document. This is necessary because the majority of HTML E-Mails uses a
* table based layout. Prefix your table selectors with an . for the class
* and with a # for the id attribute. All other tables are ignored.
- * You can assign true to this attribute to select all tables. Default: []
+ * You can assign true to this attribute to select all tables. Default: []
*/
- tables?: Array | boolean;
+ tables?: string[] | boolean;
/**
* By default links are translated the following
@@ -75,33 +55,103 @@ interface HtmlToTextOptions {
* Ignore all document images if true.
*/
ignoreImage?: boolean;
-
+
/**
* Dont print brackets around the link if true
*/
noLinkBrackets?: boolean;
-
+
/**
* By default, any newlines \n in a block of text will be removed.
* If true, these newlines will not be removed.
*/
preserveNewlines?: boolean;
-
+
/**
- * By default, headings (, , etc) are uppercased.
+ * By default, headings (, , etc) are upper-cased.
* Set to false to leave headings as they are.
*/
uppercaseHeadings?: boolean;
-
+
/**
* By default, paragraphs are converted with two newlines (\n\n).
* Set to true to convert to a single newline.
*/
singleNewLineParagraphs?: boolean;
+
+ /**
+ * defines the tags whose text content will be captured from the html.
+ * All content will be captured below the baseElement tags and added to the
+ * resulting text output. This option allows the user to specify an array
+ * of elements as base elements using a single tag with css class and id
+ * parameters e.g. `[p.class1.class2#id1#id2, p.class1.class2#id1#id2]`.
+ * Default: `"body"`
+ */
+ baseElement?: string | string[];
+
+ /**
+ * convert the entire document if we don't find the tag we're looking for
+ * if true
+ */
+ returnDomByDefault?: boolean;
+
+ /**
+ * defines the text decoding options given to `he.decode`
+ * For more information see the [he](https://github.com/mathiasbynens/he) module
+ */
+ decodeOptions?: {
+ isAttributeValue: boolean;
+ strict: boolean;
+ };
+
+ /**
+ * describes how to wrap long words
+ */
+ longWordSplit?: {
+ /**
+ * an array containing the characters that may be wrapped on.
+ * These are used in order.
+ */
+ wrapCharacters: string[];
+ /**
+ * defines whether to break long words on the limit if true.
+ */
+ forceWrapOnLimit: boolean;
+ };
+
+ /**
+ * Customize the formatting of individual element types.
+ */
+ format?: Formatters;
+
+ /**
+ * defines the string that is used as item prefix for unordered lists ``.
+ * Default: ' * '
+ */
+ unorderedListItemPrefix?: string;
}
-declare module "html-to-text" {
- export = htmlToText;
+export interface Formatters {
+ text?: LeafFormatter;
+ image?: LeafFormatter;
+ lineBreak?: Formatter;
+ paragraph?: Formatter;
+ anchor?: Formatter;
+ heading?: Formatter;
+ table?: Formatter;
+ orderedList?: Formatter;
+ unorderedList?: Formatter;
+ listItem?: Formatter;
+ horizontalLine?: Formatter;
}
-declare var htmlToText: HtmlToTextStatic;
+export type LeafFormatter = (
+ el: T,
+ options: HtmlToTextOptions
+) => string;
+
+export type Formatter = (
+ el: T,
+ walk: (dom: any[], options: HtmlToTextOptions) => string,
+ options: HtmlToTextOptions
+) => string;
diff --git a/types/html-to-text/lib/formatter.d.ts b/types/html-to-text/lib/formatter.d.ts
new file mode 100644
index 0000000000..75824eba5d
--- /dev/null
+++ b/types/html-to-text/lib/formatter.d.ts
@@ -0,0 +1,13 @@
+import { Formatter, LeafFormatter } from '..';
+
+export const text: LeafFormatter;
+export const image: LeafFormatter;
+export const lineBreak: Formatter;
+export const paragraph: Formatter;
+export const anchor: Formatter;
+export const heading: Formatter;
+export const table: Formatter;
+export const orderedList: Formatter;
+export const unorderedList: Formatter;
+export const listItem: Formatter;
+export const horizontalLine: Formatter;
diff --git a/types/html-to-text/tslint.json b/types/html-to-text/tslint.json
index 609ca3b83c..f93cf8562a 100644
--- a/types/html-to-text/tslint.json
+++ b/types/html-to-text/tslint.json
@@ -1,17 +1,3 @@
{
- "extends": "dtslint/dt.json",
- "rules": {
- "array-type": false,
- "ban-types": false,
- "callable-types": false,
- "dt-header": false,
- "no-consecutive-blank-lines": false,
- "no-declare-current-package": false,
- "no-redundant-jsdoc": false,
- "no-single-declare-module": false,
- "no-trailing-whitespace": false,
- "prefer-const": false,
- "prefer-method-signature": false,
- "trim-file": false
- }
-}
\ No newline at end of file
+ "extends": "dtslint/dt.json"
+}