mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-29 11:12:23 +08:00
added module html-to-text
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<script>
|
||||
function myFunction {
|
||||
document.getElementById("demo").innerHTML = "Hello JavaScript!";
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
<b>bold</b>
|
||||
</p>
|
||||
<p>
|
||||
<i>italic</i>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/// <reference path="html-to-text.d.ts" />
|
||||
|
||||
import * as htmlToText from 'html-to-text';
|
||||
|
||||
let htmlOptions: HtmlToTextOptions = {
|
||||
wordwrap: null,
|
||||
tables: true,
|
||||
hideLinkHrefIfSameAsText: true,
|
||||
ignoreImage: true
|
||||
};
|
||||
|
||||
|
||||
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 = "<p><b>bold</b></p><p><i>italic</i></p>";
|
||||
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));
|
||||
|
||||
Vendored
+84
@@ -0,0 +1,84 @@
|
||||
// Type definitions for html-to-text v1.4.0
|
||||
// Project: https://github.com/werk85/node-html-to-text
|
||||
// Definitions by: Eryk Warren <https://github.com/erykwarren/>
|
||||
// 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;
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
wordwrap?: number;
|
||||
|
||||
/**
|
||||
* Allows to select certain tables by the class or id attribute from the HTML
|
||||
* 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: []
|
||||
*/
|
||||
tables?: Array<string> | boolean;
|
||||
|
||||
/**
|
||||
* By default links are translated the following
|
||||
* <a href='link'>text</a> => becomes => text [link].
|
||||
* If this option is set to true and link and text are the same,
|
||||
* [link] will be hidden and only text visible.
|
||||
*/
|
||||
hideLinkHrefIfSameAsText?: boolean;
|
||||
|
||||
/**
|
||||
* Allows you to specify the server host for href attributes, where the links start at the root (/).
|
||||
* For example, linkHrefBaseUrl = 'http://asdf.com' and <a href='/dir/subdir'>...</a>
|
||||
* the link in the text will be http://asdf.com/dir/subdir.
|
||||
* Keep in mind that linkHrefBaseUrl shouldn't end with a /.
|
||||
*/
|
||||
linkHrefBaseUrl?: string;
|
||||
|
||||
/**
|
||||
* Ignore all document links if true.
|
||||
*/
|
||||
ignoreHref?: boolean;
|
||||
|
||||
/**
|
||||
* Ignore all document images if true.
|
||||
*/
|
||||
ignoreImage?: boolean;
|
||||
}
|
||||
|
||||
declare module "html-to-text" {
|
||||
export = htmlToText;
|
||||
}
|
||||
|
||||
declare var htmlToText: HtmlToTextStatic;
|
||||
Reference in New Issue
Block a user