Phiên bản 8 mang đến sự hỗ trợ của bộ chọn để tăng tính linh hoạt lên rất nhiều nhưng điều đó cũng thay đổi một số thứ được giới thiệu trong phiên bản 6. Lựa chọn [các] phần tử cơ sở cũng có những thay đổi quan trọng
Phiên bản 9 loại bỏ rất nhiều tùy chọn không dùng nữa, giới thiệu một số trình định dạng mới và khả năng mới cho các trình định dạng tùy chỉnh. Bây giờ là gói chế độ kép [cjs và esm]. CLI được chuyển sang một gói riêng
Cài đặt
npm install html-to-text
Cách sử dụng
Chuyể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 = 'Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
Định cấu hình html-to-text
một lần để xử lý hàng loạt [được khuyến nghị để có hiệu suất tốt]
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ 'Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
Tùy chọn
tùy chọn chung
OptionDefaultDescription_______247_______Mô tả phần nào của tài liệu đầu vào phải được chuyển đổi và trình bày trong văn bản đầu ra, và theo thứ tự nào.baseElements.selectors
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '0Các phần tử khớp với bất kỳ bộ chọn nào được cung cấp sẽ được xử lý và đưa vào văn bản đầu ra, với tất cả nội dung bên trongHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
Tham khảo phần bên dưới.
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '1Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '2Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '2 - sắp xếp các phần tử cơ sở theo cùng thứ tự như mảngHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
baseElements.selectors
;const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '5 - sắp xếp các phần tử cơ sở theo thứ tự chúng được tìm thấy trong tài liệu đầu vào.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '6Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '7Chuyển đổi toàn bộ tài liệu nếu không có bộ chọn nào được cung cấp phù hợp.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '8Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '7Giải mã các thực thể HTML được tìm thấy trong HTML đầu vào nếuHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '7. Nếu không thì giữ nguyên trong văn bản đầu ra.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '1Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '2Một từ điển có các ký tự cần được thay thế trong văn bản đầu ra và các chuỗi thoát tương ứng.Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '3_______2_______2Một đối tượng có chức năng định dạng tùy chỉnh cho các phần tử cụ thể [xem phần bên dưới].Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '5Mô tả cách giới hạn văn bản đầu ra trong trường hợp tài liệu HTML lớn.Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '6Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '7Một chuỗi để chèn vào vị trí của nội dung bị bỏ qua.Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '8Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '9 Ngừng tìm kiếm thêm các yếu tố cơ bản sau khi đạt đến số tiền này. Không giới hạn nếu không xác định.Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { convert } = require['html-to-text']; const html = 'PageAction'; const text = convert[html, { selectors: [ { selector: 'a', options: { baseUrl: '//example.com' } }, { selector: 'a.button', format: 'skip' } ] }]; console.log[text]; // Page [//example.com/page.html]0_______2_______9Số nút con tối đa của một nút duy nhất được thêm vào đầu ra. Không giới hạn nếu không xác định.
const { convert } = require['html-to-text']; const html = 'PageAction'; const text = convert[html, { selectors: [ { selector: 'a', options: { baseUrl: '//example.com' } }, { selector: 'a.button', format: 'skip' } ] }]; console.log[text]; // Page [//example.com/page.html]2_______2_______9 Ngừng tìm kiếm các nút để thêm vào đầu ra bên dưới độ sâu này trong cây DOM. Không giới hạn nếu không xác định.
const { convert } = require['html-to-text']; const html = 'PageAction'; const text = convert[html, { selectors: [ { selector: 'a', options: { baseUrl: '//example.com' } }, { selector: 'a.button', format: 'skip' } ] }]; console.log[text]; // Page [//example.com/page.html]4
const { convert } = require['html-to-text']; const html = 'PageAction'; const text = convert[html, { selectors: [ { selector: 'a', options: { baseUrl: '//example.com' } }, { selector: 'a.button', format: 'skip' } ] }]; console.log[text]; // Page [//example.com/page.html]5Nếu chuỗi đầu vào dài hơn giá trị này - nó sẽ bị cắt bớt và một thông báo sẽ được gửi tới
const { convert } = require['html-to-text']; const html = 'PageAction'; const text = convert[html, { selectors: [ { selector: 'a', options: { baseUrl: '//example.com' } }, { selector: 'a.button', format: 'skip' } ] }]; console.log[text]; // Page [//example.com/page.html]6. Dấu chấm lửng không dùng trong trường hợp này. Không giới hạn nếu không xác định.
const { convert } = require['html-to-text']; const html = 'PageAction'; const text = convert[html, { selectors: [ { selector: 'a', options: { baseUrl: '//example.com' } }, { selector: 'a.button', format: 'skip' } ] }]; console.log[text]; // Page [//example.com/page.html]7Mô tả cách ngắt các từ dài.
const { convert } = require['html-to-text']; const html = 'PageAction'; const text = convert[html, { selectors: [ { selector: 'a', options: { baseUrl: '//example.com' } }, { selector: 'a.button', format: 'skip' } ] }]; console.log[text]; // Page [//example.com/page.html]8
const { convert } = require['html-to-text']; const html = 'PageAction'; const text = convert[html, { selectors: [ { selector: 'a', options: { baseUrl: '//example.com' } }, { selector: 'a.button', format: 'skip' } ] }]; console.log[text]; // Page [//example.com/page.html]9Một mảng chứa các ký tự có thể được bao bọc trên. Đã kiểm tra theo thứ tự, tìm kiếm sẽ dừng khi có thể đáp ứng yêu cầu về độ dài dòng.
const { convert } = require['html-to-text']; const html = 'Hello World'; 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!0_______32_______1Ngắt 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 ngắt tốt hơn.
const { convert } = require['html-to-text']; const html = 'Hello World'; 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!2_______32_______1Theo mặc định, bất kỳ dòng mới nào
const { convert } = require['html-to-text']; const html = 'Hello World'; 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 từ HTML đầu vào đều được thu gọn vào khoảng trắng giống như bất kỳ ký tự khoảng trắng HTML nào khác. Nếu
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '7, những dòng mới này sẽ được giữ nguyên ở đầu ra. Điều này chỉ hữu ích khi HTML đầu vào mang một số định dạng văn bản thuần túy thay vì các thẻ thích hợp.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; const html = 'Hello World'; 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!6_______22_______9Mô tả cách định dạng các phần tử HTML khác nhau. Xem phần bên dưới.
const { convert } = require['html-to-text']; const html = 'Hello World'; 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 { convert } = require['html-to-text']; const html = 'Hello World'; 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!9Một chuỗi ký tự được nhận dạng là khoảng trắng HTML. Giá trị mặc định sử dụng tập hợp các ký tự được xác định trong. [Nó bao gồm không gian có chiều rộng bằng 0 so với. ]
import { compile, convert } from 'html-to-text'; // for batch use: const compiledConvert = compile[options]; let text = compiledConvert[html, metadata]; // for single use: let text = convert[html, options, metadata];0
import { compile, convert } from 'html-to-text'; // for batch use: const compiledConvert = compile[options]; let text = compiledConvert[html, metadata]; // for single use: let text = convert[html, options, metadata];1Sau bao nhiêu ký tự thì phải ngắt dòng
Đặt thành
import { compile, convert } from 'html-to-text'; // for batch use: const compiledConvert = compile[options]; let text = compiledConvert[html, metadata]; // for single use: let text = convert[html, options, metadata];2 hoặc
const { convert } = require['html-to-text']; const html = 'Hello World'; 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!1 để tắt tính năng ngắt từ
Các tùy chọn không dùng nữa hoặc đã bị xóa
Tùy chọn cũDepr. Rem. Thay vào đó, hãy sử dụng_______42_______48. 0____42_______5import { compile, convert } from 'html-to-text'; // for batch use: const compiledConvert = compile[options]; let text = compiledConvert[html, metadata]; // for single use: let text = convert[html, options, metadata];69. 0Việc giải mã thực thể hiện được xử lý bởi chính htmlparser2 và các thực thể bên trong. Không có phần nào người dùng có thể định cấu hình so với anh ấy ngoài boolean
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '8.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
import { compile, convert } from 'html-to-text'; // for batch use: const compiledConvert = compile[options]; let text = compiledConvert[html, metadata]; // for single use: let text = convert[html, options, metadata];86. 0Cách viết các trình định dạng đã thay đổi hoàn toàn. Các trình định dạng mới phải được thêm vào tùy chọn
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '3, các trình định dạng cũ không thể được sử dụng lại mà không viết lại. Xem bên dưới.Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const options = { // ... formatters: { filterBlockFormatter: function [elem, walk, builder, formatOptions] { // all built-in and custom formatters available by name const blockFormatter = builder.options.formatters['block']; if [blockFormatter && elem.children.some[/* predicate */]] { blockFormatter[elem, walk, builder, formatOptions]; } } }, selectors: [ { selector: 'div.questionable', format: 'filterBlockFormatter', options: { leadingLineBreaks: 1, trailingLineBreaks: 1 } } ], // ... }06. 09. 0____52_______1
const options = { // ... formatters: { filterBlockFormatter: function [elem, walk, builder, formatOptions] { // all built-in and custom formatters available by name const blockFormatter = builder.options.formatters['block']; if [blockFormatter && elem.children.some[/* predicate */]] { blockFormatter[elem, walk, builder, formatOptions]; } } }, selectors: [ { selector: 'div.questionable', format: 'filterBlockFormatter', options: { leadingLineBreaks: 1, trailingLineBreaks: 1 } } ], // ... }26. 09. 0____52_______3
const options = { // ... formatters: { filterBlockFormatter: function [elem, walk, builder, formatOptions] { // all built-in and custom formatters available by name const blockFormatter = builder.options.formatters['block']; if [blockFormatter && elem.children.some[/* predicate */]] { blockFormatter[elem, walk, builder, formatOptions]; } } }, selectors: [ { selector: 'div.questionable', format: 'filterBlockFormatter', options: { leadingLineBreaks: 1, trailingLineBreaks: 1 } } ], // ... }46. 09. 0____52_______5_______52_______66. 09. 0____52_______7
const options = { // ... formatters: { filterBlockFormatter: function [elem, walk, builder, formatOptions] { // all built-in and custom formatters available by name const blockFormatter = builder.options.formatters['block']; if [blockFormatter && elem.children.some[/* predicate */]] { blockFormatter[elem, walk, builder, formatOptions]; } } }, selectors: [ { selector: 'div.questionable', format: 'filterBlockFormatter', options: { leadingLineBreaks: 1, trailingLineBreaks: 1 } } ], // ... }8
const options = { // ... formatters: { filterBlockFormatter: function [elem, walk, builder, formatOptions] { // all built-in and custom formatters available by name const blockFormatter = builder.options.formatters['block']; if [blockFormatter && elem.children.some[/* predicate */]] { blockFormatter[elem, walk, builder, formatOptions]; } } }, selectors: [ { selector: 'div.questionable', format: 'filterBlockFormatter', options: { leadingLineBreaks: 1, trailingLineBreaks: 1 } } ], // ... }9
html-to-text
0____246_______16. 09. 0____246_______2______246_______36. 09. 0____246_______4____246_______58. 0____246_______6_______246_______76. 09. 0____52_______7html-to-text
9baseElements
0html-to-text
0____247_______28. 0____247_______3_______247_______48. 0Xem phần bên dưới. baseElements
56. 09. 0____247_______6_______247_______76. 09. 0____52_______7baseElements
9baseElements.selectors
0baseElements.selectors
1html-to-text
0Những thứ khác đã bị xóa
- Phương pháp
baseElements.selectors
3 - thay vào đó hãy sử dụngbaseElements.selectors
4 hoặcbaseElements.selectors
5; - các đối số vị trí trong các phương thức
baseElements.selectors
6 - thay vào đó hãy truyền các đối tượng tùy chọn
Bộ chọn
Một số ví dụ
const { convert } = require['html-to-text']; const html = 'PageAction'; const text = convert[html, { selectors: [ { selector: 'a', options: { baseUrl: '//example.com' } }, { selector: 'a.button', format: 'skip' } ] }]; console.log[text]; // Page [//example.com/page.html]
Mảng bộ chọn là xấp xỉ lỏng lẻo của chúng tôi về biểu định kiểu
- bộ chọn cao nhất được sử dụng khi có nhiều kết quả phù hợp;
- bộ chọn cuối cùng được sử dụng khi có nhiều kết quả khớp có độ đặc hiệu như nhau;
- tất cả các mục có cùng giá trị bộ chọn được hợp nhất [đệ quy] ở giai đoạn biên dịch, theo cách đó, các thuộc tính được xác định cuối cùng được giữ nguyên và thứ tự tương đối của các bộ chọn duy nhất được giữ nguyên;
- các mục nhập do người dùng xác định được thêm vào sau;
- Mỗi bộ chọn duy nhất phải có giá trị
import { compile, convert } from 'html-to-text'; // for batch use: const compiledConvert = compile[options]; let text = compiledConvert[html, metadata]; // for single use: let text = convert[html, options, metadata];
8 được chỉ định [ít nhất một lần]; - không giống như trong CSS, các giá trị từ các bộ chọn phù hợp khác nhau KHÔNG được hợp nhất ở giai đoạn chuyển đổi. Thay vào đó, trận đấu tốt nhất đơn lẻ được sử dụng [đó là trận đấu cuối cùng trong số những trận đấu có độ đặc hiệu cao nhất]
Để đạt được hiệu suất tốt nhất khi kiểm tra từng phần tử DOM dựa trên các bộ chọn được cung cấp, chúng được biên dịch thành một cây quyết định. Nhưng điều quan trọng là cách bạn chọn bộ chọn. Ví dụ: baseElements.selectors
8 tốt hơn nhiều so với baseElements.selectors
9 - cái trước sẽ chỉ kiểm tra div cho id trong khi cái sau phải kiểm tra mọi thành phần trong DOM
_____ 246 _____ dựa vào các gói rau mùi tây và selderee để hỗ trợ bộ chọn
Các bộ chọn sau có thể được sử dụng trong bất kỳ kết hợp nào
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '
01 - bộ chọn phổ quát;Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello Worldconst { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '
02 - thẻ tên;Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello Worldconst { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '
03 - tên lớp;Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello Worldconst { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '
04 - id;Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello Worldconst { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '
05 - sự hiện diện của thuộc tính;Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello Worldconst { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '
06 - giá trị thuộc tính [với bất kỳ toán tử nào cũng như dấu ngoặc kép và bộ điều chỉnh độ phân biệt chữ hoa chữ thường];Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World- Bộ kết hợp
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '
07 vàHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello Worldconst { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '
08 [các bộ kết hợp khác không được hỗ trợ]Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
Ví dụ, bạn có thể khớp
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '09 vớiHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '10định dạng được xác định trướcHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
Các bộ chọn sau có bộ định dạng được chỉ định như một phần của cấu hình mặc định. Mọi thứ đều có thể bị ghi đè, nhưng bạn không cần phải lặp lại
import { compile, convert } from 'html-to-text'; // for batch use: const compiledConvert = compile[options]; let text = compiledConvert[html, metadata]; // for single use: let text = convert[html, options, metadata];8 hoặc các tùy chọn mà bạn không muốn ghi đè. [Nhưng hãy nhớ rằng điều này chỉ đúng với cùng một bộ chọn. Không có kết nối giữa các bộ chọn khác nhau. ]SelectorDefault formatNotes
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '01Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '13Universal selector.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '14Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '15Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '16Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '17Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '18Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '17Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '20Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '20Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '22Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '23Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '02Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '17Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '26Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '17Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '28Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '17Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '30Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '31Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '32Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '31Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '34Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '31Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '36Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '31Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '38Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '31Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '40Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '31Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '42Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '17Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '44Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '45Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '46Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '47Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '48Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '17Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '50Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '17Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '52Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '53Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '54Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '55Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '56Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '56Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '58Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '58Equivalent toHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '17. Sử dụngHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '61 thay cho dữ liệu dạng bảng.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '62Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '63Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '64Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '64Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
Nhiều trình định dạng khác cũng có sẵn để sử dụng
Định dạngMô tảconst { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '61Dành cho các bảng trực quan chính xác. Lưu ý rằng điều này có thể không thân thiện với tìm kiếm [văn bản đầu ra sẽ giống như vô nghĩa đối với máy khi có bất kỳ nội dung ô nào được bao bọc] và cũng tốt hơn nên tránh đối với các bảng được sử dụng làm công cụ bố cục trang.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '67Bỏ qua thẻ đã cho với nội dung của nó mà không in bất cứ thứ gì.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '68Chèn một khối với chuỗi ký tự đã cho [Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '69] thay vì thẻ.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '70Kết xuất một phần tử dưới dạng túi khối HTML, chuyển đổi nội dung của nó thành văn bản.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '71Kết xuất một phần tử với tất cả các phần tử con dưới dạng khối HTML.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '72Chèn nội tuyến chuỗi ký tự đã cho [Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '69] thay vì thẻ.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '74Kết xuất phần tử nội tuyến được bọc bằng các chuỗi đã cho [Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '75 vàHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '76].Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '77Kết xuất một phần tử dưới dạng thẻ HTML nội tuyến, chuyển đổi nội dung của nó thành văn bản.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '78Kết xuất một phần tử với tất cả các phần tử con dưới dạng HTML nội tuyếnTùy chọn định dạngHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
Các tùy chọn sau có sẵn cho các trình định dạng tích hợp
Tùy chọnMặc địnhÁp dụng cho Mô tảconst { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '79Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '80,Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '81 hoặcHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '82tất cả các trình định dạng cấp khốiSố lượng ngắt dòng để tách khối trước đó khỏi khối nàyHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
Lưu ý rằng cần có N+1 ngắt dòng để tạo N dòng trống.
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '83Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '80 hoặcHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '81tất cả các trình định dạng cấp khối Số lượng ngắt dòng để tách khối này khỏi khối tiếp theoHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
Lưu ý rằng cần có N+1 ngắt dòng để tạo N dòng trống.
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '86Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
import { compile, convert } from 'html-to-text'; // for batch use: const compiledConvert = compile[options]; let text = compiledConvert[html, metadata]; // for single use: let text = convert[html, options, metadata];2
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '15,Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '47Máy chủ lưu trữ liên kếtHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '90 thuộc tính và hình ảnhHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '91 thuộc tính liên quan đến thư mục gốc [những thuộc tính bắt đầu bằngHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '92]Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
Ví dụ, với
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '93 vàHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '94 thì liên kết trong văn bản sẽ làHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '95.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '96Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '97Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '15,Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '47Liên kết bao quanh với các dấu ngoặc nàyHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
Đặt thành
const { convert } = require['html-to-text']; const html = 'Hello World'; 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!1 hoặc
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '01 để tắt.Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '02_______2_______9Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '15,Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '47Một chức năng để viết lại liên kếtHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '90 thuộc tính và hình ảnhHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '91 thuộc tính. Đối số thứ hai tùy chọn là đối tượng siêu dữ liệuHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
Áp dụng trước
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '86.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const options = { // ... formatters: { filterBlockFormatter: function [elem, walk, builder, formatOptions] { // all built-in and custom formatters available by name const blockFormatter = builder.options.formatters['block']; if [blockFormatter && elem.children.some[/* predicate */]] { blockFormatter[elem, walk, builder, formatOptions]; } } }, selectors: [ { selector: 'div.questionable', format: 'filterBlockFormatter', options: { leadingLineBreaks: 1, trailingLineBreaks: 1 } } ], // ... }0
const { convert } = require['html-to-text']; const html = 'Hello World'; 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!1
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '15Theo mặc định, các liên kết được dịch theo cách sauHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '12 => trở thành =>Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '13Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
Nếu tùy chọn này được đặt thành
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '7 vàHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '15 vàHello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '16 giống nhau, thìHello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '17 sẽ bị bỏ qua và chỉ cóHello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '16.Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const options = { // ... formatters: { filterBlockFormatter: function [elem, walk, builder, formatOptions] { // all built-in and custom formatters available by name const blockFormatter = builder.options.formatters['block']; if [blockFormatter && elem.children.some[/* predicate */]] { blockFormatter[elem, walk, builder, formatOptions]; } } }, selectors: [ { selector: 'div.questionable', format: 'filterBlockFormatter', options: { leadingLineBreaks: 1, trailingLineBreaks: 1 } } ], // ... }2
const { convert } = require['html-to-text']; const html = 'Hello World'; 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!1
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '15Ignore all links. Chỉ xử lý văn bản nội bộ của thẻ neo.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
html-to-text
1const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '7Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '15Bỏ qua các liên kết neo [trong đóHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '25].Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '26____2_______27Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '63Chuỗi tiền tố cho mỗi mục danh sách.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '29_______1_______7Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '31Theo mặc định, tiêu đề [Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '32,Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '33, v.v.] được viết hoaHello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
Đặt cái này thành
const { convert } = require['html-to-text']; const html = 'Hello World'; 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!1 để giữ nguyên tiêu đề.
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '35Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '9Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '45Length of the line. Nếu không xác định thì giá trịHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
import { compile, convert } from 'html-to-text'; // for batch use: const compiledConvert = compile[options]; let text = compiledConvert[html, metadata]; // for single use: let text = convert[html, options, metadata];0 được sử dụng. Giảm về 40 nếu điều đó cũng bị vô hiệu hóa.
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '39_______1_______7Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '20Cắt các dòng trống khỏi blockquoteHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
Mặc dù các dòng trống nên được giữ nguyên trong HTML, hành vi tiết kiệm không gian được chọn làm mặc định để thuận tiện.
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '42_______1_______7Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '61Theo mặc định, các ô tiêu đề [_______2_______45] được viết hoaHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
Đặt giá trị này thành
const { convert } = require['html-to-text']; const html = 'Hello World'; 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!1 để giữ nguyên các ô tiêu đề.
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '47_______2_______48Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '61Nội dung ô của bảng dữ liệu sẽ được bao bọc để vừa với chiều rộng này thay vì giới hạn toàn cầuHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
import { compile, convert } from 'html-to-text'; // for batch use: const compiledConvert = compile[options]; let text = compiledConvert[html, metadata]; // for single use: let text = convert[html, options, metadata];0
Đặt giá trị này thành
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '9 để giảm về giới hạnHello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
import { compile, convert } from 'html-to-text'; // for batch use: const compiledConvert = compile[options]; let text = compiledConvert[html, metadata]; // for single use: let text = convert[html, options, metadata];0.
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '53Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '82Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '61Số khoảng cách giữa các cột trong bảng dữ liệu.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '56Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '57Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '61Số dòng trống giữa các hàng của bảng dữ liệu.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '59Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '60Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '68,Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '72Một chuỗi được chèn vào vị trí của thẻ.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '63Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '60Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '74Tiền tố chuỗi được chèn trước nội dung thẻ nội tuyến.Hello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '66Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '60Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { convert } = require['html-to-text']; // There is also an alias to `convert` called `htmlToText`. const html = '74Hậu tố chuỗi sẽ được chèn sau nội dung thẻ nội tuyếnTùy chọn định dạng không dùng nữaTùy chọn cũ Áp dụng cho Depr. Rem. Thay vào đó hãy sử dụngHello World
'; const text = convert[html, { wordwrap: 130 }]; console.log[text]; // Hello World
html-to-text
3_______1_______158. 1____2_______71ghi đè định dạng
Tùy chọn
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '3 là đối tượng chứa chức năng định dạng. Chúng có thể được chỉ định để định dạng các phần tử khác nhau trong mảngHello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { convert } = require['html-to-text']; const html = 'Hello World'; 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!6
Mỗi trình định dạng là một hàm gồm bốn đối số không trả về gì. Đối số là
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '
74 - phần tử HTML được xử lý bởi trình định dạng này;Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '
75 - hàm đệ quy để xử lý phần tử con của phần tử này. Được gọi làHello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '
76;Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '
77 - Đố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;Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '
78 - các tùy chọn được chỉ định cho thẻ, cùng với trình định dạng này [Lưu ý. nếu bạn cần chuyển html thành văn bản chung - bạn có thể truy cập chúng quaHello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '
79]Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
Ví dụ về trình định dạng tùy chỉnh
const { convert } = require['html-to-text']; const html = 'Hello World'; 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!
Mới trong phiên bản 9. đối tượng siêu dữ liệu có thể được cung cấp làm đối số tùy chọn cuối cùng của hàm baseElements.selectors
4 [hoặc hàm được trả về bởi hàm
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '81]. Nó có thể được truy cập bởi các trình định dạng dưới dạngHello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
const { compile } = require['html-to-text']; const convert = compile[{ wordwrap: 130 }]; const htmls = [ '82Hello World!
', 'こんにちは世界!
', 'Привет, мир!
' ]; const texts = htmls.map[convert]; console.log[texts.join['\n']]; // Hello World! // こんにちは世界! // Привет, мир!
Tham khảo các trình định dạng chung của gói cơ sở và các trình định dạng văn bản của gói này để 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
Siêu dữ liệu tùy chỉnh
Nếu bạn cần cung cấp thêm thông tin về tài liệu HTML của mình để sử dụng trong các trình định dạng tùy chỉnh - bạn có thể thực hiện việc này với sự trợ giúp của đối tượng siêu dữ liệu