Show
Chuyển đổi nâng cao phân tích HTML và trả về văn bản đẹp. Đặc trưng
Thay đổiCó sẵn ở đây: changelog.md Phiên bản 6 chứa rất nhiều thay đổi, vì vậy nó đáng để xem xét. Phiên bản 7 chứa một thay đổi quan trọng cho các định dạng tùy chỉnh. Phiên bản 8 mang lại cho các bộ chọn hỗ trợ để tăng đáng kể tính linh hoạt nhưng điều đó cũng thay đổi một số điều được giới thiệu trong phiên bản 6. Lựa chọn phần tử cơ sở cũng có những thay đổi quan trọng. Cài đặt
Cách sử dụngChuyển đổi một tài liệu duy nhất: const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World Định cấu hình const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир! Tùy chọnTùy chọn chung
Phá vỡ các từ dài ở giới hạn độ dài dòng trong trường hợp không tìm thấy cơ hội bọc tốt hơn.
|
Bộ chọn | Default format | Ghi chú |
---|---|---|
baseElements.selectors 5 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World07 | Bộ chọn phổ quát. |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World08 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World09 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World10 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World11 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World12 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World11 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World12 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World12 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World14 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World16 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World17 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World11 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World12 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World11 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World12 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World11 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World12 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World14 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World12 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World14 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World16 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World14 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World16 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World14 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World16 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World14 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World16 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World14 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World16 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World11 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World12 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World14 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World16 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World17 | |
baseElements.selectors 6 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World11 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World12 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World11 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World12 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World14 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World16 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World17 | |
baseElements.selectors 6 | baseElements.selectors 6 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World20 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World20 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World22 |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World24 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World25 | |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World28 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World28 |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World30
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World
32const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World
34
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.
const html = '<h2>Hello World</h2>';
const text = convert(html, {
wordwrap: 130
});
console.log(text); // Hello World
36
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World38
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World39 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World40 | Applies to | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World41 |
---|---|---|---|
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World42 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World44 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World46 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World47 Note that N+1 line breaks are needed to make N empty lines. |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World48 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World49 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World46 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World47 Note that N+1 line breaks are needed to make N empty lines. |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World48 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World49 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World50 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World52 For example, with const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World76 and const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World77 the link in the text will be const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World78. Keep in mind that const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World69 should not end with a const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World75. |
Tương đương với const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World11. Sử dụng const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World55 thay thế cho dữ liệu bảng. | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World56 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World50 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World52 Set to const { convert } = require('html-to-text'); const html = '<a href="/page.html">Page</a><a href="!#" class="button">Action</a>'; const text = convert(html, { selectors: [ { selector: 'a', options: { baseUrl: 'https://example.com' } }, { selector: 'a.button', format: 'skip' } ] }); console.log(text); // Page [https://example.com/page.html]9 or const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World86 to disable. |
Tương đương với const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World11. Sử dụng const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World55 thay thế cho dữ liệu bảng. | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World56 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World09 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World10 const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World90 => becomes => const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World91. If this option is set to const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World7 and const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World93 and const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World94 are the same, const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World95 will be omitted and only const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World94 will be present. |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World11 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World56 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World09 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World10 |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World11 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World12 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World09 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World10 |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World11 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World12 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World25 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World28 |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World30 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World12 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World14 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World16 Set this to const { convert } = require('html-to-text'); const html = '<a href="/page.html">Page</a><a href="!#" class="button">Action</a>'; const text = convert(html, { selectors: [ { selector: 'a', options: { baseUrl: 'https://example.com' } }, { selector: 'a.button', format: 'skip' } ] }); console.log(text); // Page [https://example.com/page.html]9 to leave headings as they are. |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World17 | baseElements.selectors 6 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World14 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World16 |
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World17 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World12 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World12 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World14 While empty lines should be preserved in HTML, space-saving behavior is chosen as default for convenience. |
const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!20 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World7 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World55 | Theo mặc định, các ô tiêu đề (const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!23) được sử dụng trên đường. Điều này thành const { convert } = require('html-to-text'); const html = '<a href="/page.html">Page</a><a href="!#" class="button">Action</a>'; const text = convert(html, { selectors: [ { selector: 'a', options: { baseUrl: 'https://example.com' } }, { selector: 'a.button', format: 'skip' } ] }); console.log(text); // Page [https://example.com/page.html]9 để để lại các tế bào tiêu đề như chúng. Set this to const { convert } = require('html-to-text'); const html = '<a href="/page.html">Page</a><a href="!#" class="button">Action</a>'; const text = convert(html, { selectors: [ { selector: 'a', options: { baseUrl: 'https://example.com' } }, { selector: 'a.button', format: 'skip' } ] }); console.log(text); // Page [https://example.com/page.html]9 to leave heading cells as they are. |
const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!25 | const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!26 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World55 | Theo mặc định, các ô tiêu đề (const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!23) được sử dụng trên đường. Điều này thành const { convert } = require('html-to-text'); const html = '<a href="/page.html">Page</a><a href="!#" class="button">Action</a>'; const text = convert(html, { selectors: [ { selector: 'a', options: { baseUrl: 'https://example.com' } }, { selector: 'a.button', format: 'skip' } ] }); console.log(text); // Page [https://example.com/page.html]9 để để lại các tế bào tiêu đề như chúng. Set this to const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!7 in order to fall back to const { convert } = require('html-to-text'); const html = '<foo>Hello World</foo>'; const text = convert(html, { formatters: { // Create a formatter. 'fooBlockFormatter': function (elem, walk, builder, formatOptions) { builder.openBlock({ leadingLineBreaks: formatOptions.leadingLineBreaks || 1 }); walk(elem.children, builder); builder.addInline('!'); builder.closeBlock({ trailingLineBreaks: formatOptions.trailingLineBreaks || 1 }); } }, selectors: [ // Assign it to `foo` tags. { selector: 'foo', format: 'fooBlockFormatter', options: { leadingLineBreaks: 1, trailingLineBreaks: 1 } } ] }); console.log(text); // Hello World!8 limit. |
const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!25 | const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!26 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World55 | Theo mặc định, các ô tiêu đề (const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!23) được sử dụng trên đường. Điều này thành const { convert } = require('html-to-text'); const html = '<a href="/page.html">Page</a><a href="!#" class="button">Action</a>'; const text = convert(html, { selectors: [ { selector: 'a', options: { baseUrl: 'https://example.com' } }, { selector: 'a.button', format: 'skip' } ] }); console.log(text); // Page [https://example.com/page.html]9 để để lại các tế bào tiêu đề như chúng. |
const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!25 | const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!26 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World55 | Theo mặc định, các ô tiêu đề (const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!23) được sử dụng trên đường. Điều này thành const { convert } = require('html-to-text'); const html = '<a href="/page.html">Page</a><a href="!#" class="button">Action</a>'; const text = convert(html, { selectors: [ { selector: 'a', options: { baseUrl: 'https://example.com' } }, { selector: 'a.button', format: 'skip' } ] }); console.log(text); // Page [https://example.com/page.html]9 để để lại các tế bào tiêu đề như chúng. |
const { compile } = require('html-to-text');
const convert = compile({
wordwrap: 130
});
const htmls = [
'<h2>Hello World!</h2>',
'<h2>こんにちは世界!</h2>',
'<h2>Привет, мир!</h2>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
25
const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!26 | Applies to | Depr. | Rem. | Nội dung ô bảng dữ liệu sẽ được bọc để phù hợp với chiều rộng này thay vì giới hạn toàn cầu ____48. Điều này đến const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!7 để quay trở lại giới hạn const { convert } = require('html-to-text'); const html = '<foo>Hello World</foo>'; const text = convert(html, { formatters: { // Create a formatter. 'fooBlockFormatter': function (elem, walk, builder, formatOptions) { builder.openBlock({ leadingLineBreaks: formatOptions.leadingLineBreaks || 1 }); walk(elem.children, builder); builder.addInline('!'); builder.closeBlock({ trailingLineBreaks: formatOptions.trailingLineBreaks || 1 }); } }, selectors: [ // Assign it to `foo` tags. { selector: 'foo', format: 'fooBlockFormatter', options: { leadingLineBreaks: 1, trailingLineBreaks: 1 } } ] }); console.log(text); // Hello World!8. |
---|---|---|---|---|
const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!31 | const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World65 | 8.1 | Số lượng khoảng trống giữa các cột bảng dữ liệu. |
const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!34
const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!35
Số lượng dòng trống giữa các hàng bảng dữ liệu.
Tùy chọn định dạng không dùng nữa
- Tùy chọn cũ
- Thay vào đó sử dụng
9cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
const { convert } = require('html-to-text'); // There is also an alias to `convert` called `htmlToText`. const html = '<h2>Hello World</h2>'; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World
09
const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!39
const { convert } = require('html-to-text'); const html = '<foo>Hello World</foo>'; const text = convert(html, { formatters: { // Create a formatter. 'fooBlockFormatter': function (elem, walk, builder, formatOptions) { builder.openBlock({ leadingLineBreaks: formatOptions.leadingLineBreaks || 1 }); walk(elem.children, builder); builder.addInline('!'); builder.closeBlock({ trailingLineBreaks: formatOptions.trailingLineBreaks || 1 }); } }, selectors: [ // Assign it to `foo` tags. { selector: 'foo', format: 'fooBlockFormatter', options: { leadingLineBreaks: 1, trailingLineBreaks: 1 } } ] }); console.log(text); // Hello World!
Ghi đè định dạng
Điều này được thay đổi đáng kể trong phiên bản 6.
Tùy chọn
const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!1 là một đối tượng giữ các hàm định dạng. Chúng có thể được gán cho định dạng các yếu tố khác nhau trong mảng
const { convert } = require('html-to-text'); const html = '<foo>Hello World</foo>'; const text = convert(html, { formatters: { // Create a formatter. 'fooBlockFormatter': function (elem, walk, builder, formatOptions) { builder.openBlock({ leadingLineBreaks: formatOptions.leadingLineBreaks || 1 }); walk(elem.children, builder); builder.addInline('!'); builder.closeBlock({ trailingLineBreaks: formatOptions.trailingLineBreaks || 1 }); } }, selectors: [ // Assign it to `foo` tags. { selector: 'foo', format: 'fooBlockFormatter', options: { leadingLineBreaks: 1, trailingLineBreaks: 1 } } ] }); console.log(text); // Hello World!4.
Mỗi định dạng là một hàm của bốn đối số không trả về không có gì. Đối số là:
const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!42 - Phần tử HTML được xử lý bởi định dạng này;
const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!43 - Hàm đệ quy để xử lý trẻ em của yếu tố này. Được gọi là
const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!44;
cat example/test.html | html-to-text > test.txt
const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!45 - Đối tượng BlockTextBuilder. Thao tác trạng thái đối tượng này để xây dựng văn bản đầu ra;
cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!46 - Các tùy chọn được chỉ định cho một thẻ, cùng với định dạng này (Lưu ý: Nếu bạn cần các tùy chọn HTML -to -Text chung - chúng có thể truy cập thông qua
const { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!47).
Ví dụ về định dạng tùy chỉnh:
- Tham khảo các định dạng tích hợp để biết thêm ví dụ. Cách dễ nhất để viết của riêng bạn là chọn một cái hiện có và tùy chỉnh.
- Tham khảo BlockTextBuilder để biết các chức năng và đối số có sẵn.
Lưu ý: baseElements.selectors0 Có một số thay đổi quan trọng trong phiên bản 7. Các đối số vị trí không được chấp nhận và các định dạng được viết cho phiên bản 6 phải được cập nhật tương ứng để tiếp tục hoạt động sau khi cập nhật chính tiếp theo.
- Giao diện dòng lệnh
- Có thể sử dụng HTML-to-Text làm giao diện dòng lệnh. Điều này cho phép xác thực dễ dàng văn bản được tạo của bạn và tích hợp trong các hệ thống khác không chạy trên Node.js.
html-to-text
sử dụngconst { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!
50 vàconst { compile } = require('html-to-text'); const convert = compile({ wordwrap: 130 }); const htmls = [ '<h2>Hello World!</h2>', '<h2>こんにちは世界!</h2>', '<h2>Привет, мир!</h2>' ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!
51 cho dữ liệu vào và xuất. Vì vậy, bạn có thể sử dụnghtml-to-text
theo cách sau:
Ngoài ra còn có tất cả các tùy chọn có sẵn như mô tả ở trên. Bạn có thể sử dụng chúng như thế này:
Tùy chọn html-to-text
8 phải được khai báo là danh sách phân tách dấu phẩy mà không có khoảng trắng.