本文整理匯總了TypeScript中html-to-text.fromString函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript fromString函數的具體用法?TypeScript fromString怎麽用?TypeScript fromString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了fromString函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: htmlToPlaintext
export function htmlToPlaintext(html: string): string {
return fromString(html, {
tables: true,
ignoreHref: true,
wordwrap: false,
uppercaseHeadings: false,
ignoreImage: true
})
}
示例2: function
res.on('end', function () {
var html = cheerio.load(data);
var text = htmlToText.fromString(String(html('div.anyipsum-output > p')));
console.log(text);
editor.edit((eb) => {
eb.insert(editor.selection.active, text);
});
});
示例3: callback
/// <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));
示例4:
export const getLicense = () => {
return htmlToText.fromString(require('../../LICENSE.md'));
};