Hướng dẫn html-to text react npm - html-to text react npm

HTML-to-text

Hướng dẫn html-to text react npm - html-to text react npm

Chuyển đổi nâng cao phân tích HTML và trả về văn bản đẹp.

Đặc trưng

  • Thẻ nội tuyến và cấp độ khối.
  • Bảng với colspans và hàng.
  • Liên kết với cả văn bản và href.
  • Gói từ.
  • Hỗ trợ Unicode.
  • Rất nhiều tùy chọn tùy chỉnh.

Thay đổi

Có 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

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 = '<h2>Hello World</h2>';
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:

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ọn

Tùy chọn chung

Quyền muaMặc địnhSự mô tả
________số 8 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 = '<h2>Hello World</h2>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
0
Các yếu tố phù hợp với bất kỳ bộ chọn được cung cấp nào sẽ được xử lý và bao gồm trong văn bản đầu ra, với tất cả nội dung bên trong. Trao đổi phần chọn được hỗ trợ bên dưới.
Refer to Supported selectors section below.
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
1
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
2
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
2 - Sắp xếp các phần tử cơ sở theo cùng thứ tự với mảng baseElements.selectors; ________ 15 - 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.
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
5 - arrange base elements in the order they are found in the input document.
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
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 World
7
Chuyển đổi toàn bộ tài liệu nếu không có bộ chọn nào được cung cấp khớp.
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
8
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
9
Các tùy chọn giải mã văn bản được cung cấp cho
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!
// こんにちは世界!
// Привет, мир!
0. Để biết thêm thông tin, hãy xem mô -đun HE.
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
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!
// こんにちは世界!
// Привет, мир!
2
Một đối tượng có hàm định dạng tùy chỉnh cho các phần tử cụ thể (xem phần Định dạng ghi đè bên dưới).
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!
// こんにちは世界!
// Привет, мир!
3
Mô tả cách giới hạn văn bản đầu ra trong trường hợp các tài liệu HTML lớ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!
// こんにちは世界!
// Привет, мир!
4
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!
// こんにちは世界!
// Привет, мир!
5
Một chuỗi để chèn thay cho nội dung bị bỏ 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!
// こんにちは世界!
// Привет, мир!
6
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
Ngừng tìm kiếm thêm các yếu tố cơ bản sau khi đạt được số tiền này. Không giới hạn nếu không xác đị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!
// こんにちは世界!
// Привет, мир!
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!
// こんにちは世界!
// Привет, мир!
7
Ngừng tìm kiếm thêm các yếu tố cơ bản sau khi đạt được số tiền này. Không giới hạn nếu không xác đị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!
// こんにちは世界!
// Привет, мир!
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!
// こんにちは世界!
// Привет, мир!
7
Ngừng tìm kiếm thêm các yếu tố cơ bản sau khi đạt được số tiền này. Không giới hạn nếu không xác đị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!
// こんにちは世界!
// Привет, мир!
8
Số lượng nút trẻ em 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 = '<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]
0
Ngừng tìm kiếm các nút để thêm vào đầu ra 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 = '<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]
2
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]
3
Nếu chuỗi đầu vào dài hơn giá trị này - nó sẽ bị cắt và một thông báo sẽ được gửi đến
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]
4. Ellipsis không được sử 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 = '<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]
5
Mô tả cách quấn các từ dài.
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]
6
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]
7
Một mảng chứa các ký tự có thể được bọc. Được kiểm tra theo thứ tự, có thể đáp ứng các điểm dừng một lần theo yêu cầu độ dài dòng.
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]
6
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]
7
Một mảng chứa các ký tự có thể được bọc. Được kiểm tra theo thứ tự, có thể đáp ứng các điểm dừng một lần theo yêu cầu độ dài dòng.Nếu chuỗi đầu vào dài hơn giá trị này - nó sẽ bị cắt và một thông báo sẽ được gửi đến
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]
4. Ellipsis không được sử 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 = '<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]
5
Mô tả cách quấn các từ dài.
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]
6
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]
7
Một mảng chứa các ký tự có thể được bọc. Được kiểm tra theo thứ tự, có thể đáp ứng các điểm dừng một lần theo yêu cầu độ dài dòng.
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]
8
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
Set to
cat example/test.html | html-to-text > test.txt
0 or
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 disable word-wrapping.

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.

Old optionDepr.Rem.Instead use
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!
0
8.0 Theo mặc định, bất kỳ Newlines
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!
2 từ HTML đầu vào đều được thu gọn vào không gian như bất kỳ ký tự nào khác về độ nào khác. Nếu
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
7, các dòng mới này sẽ được bảo tồn trong đầ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 đơn giản thay vì các thẻ thích hợp.
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
6.0 Mô tả cách các yếu tố HTML khác nhau nên được định dạng. Xem phần Lựa chọn bên dưới.
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!
6
6.0 9.0
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!
7
Một chuỗi các ký tự được công nhận 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 tiêu chuẩn HTML4. (Nó bao gồm không gian không có chiều rộng so với tiêu chuẩn sống.)6.0 9.0
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 { 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!
9
6.0 9.0 Sau khi có bao nhiêu chars, một lần phá vỡ dòng sẽ theo sau. Đến
cat example/test.html | html-to-text > test.txt
0 hoặc
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 để vô hiệu hóa việc viết từ.
Các tùy chọn không dùng nữa hoặc bị loại bỏ6.0 9.0
cat example/test.html | html-to-text > test.txt
2
cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
4
cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
5
cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
6
cat example/test.html | html-to-text > test.txt
3
6.0 9.0
cat example/test.html | html-to-text > test.txt
4
Cách viết định dạng được viết đã thay đổi hoàn toàn. Các đị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 = [
  '<h2>Hello World!</h2>',
  '<h2>こんにちは世界!</h2>',
  '<h2>Привет, мир!</h2>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
1, những cái cũ không thể được sử dụng lại mà không viết lại. Xem hướng dẫn mới dưới đây.
6.0 9.0
cat example/test.html | html-to-text > test.txt
6
cat example/test.html | html-to-text > test.txt
7
8.0
cat example/test.html | html-to-text > test.txt
8
cat example/test.html | html-to-text > test.txt
9
6.0 9.0
cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
0
html-to-text5
html-to-text6
cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
6
cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
1
8.0
cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
2
cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
3
cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
4
cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
5
cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
6
8.0
cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
7
cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
8
6.0 9.0
cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
9
html-to-text06.0 9.0 html-to-text1
baseElements5
baseElements6
baseElements7
cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
6

html-to-text2

  • html-to-text3
  • cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
    
    3html-to-text5html-to-text6
    cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
    
    6

html-to-text8

html-to-text9

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]

baseElements0

  • Xem phần Lựa chọn bên dưới.
  • baseElements1
  • baseElements2
  • Các mục do người dùng xác định được thêm vào sau các mục được xác định trước;
  • Mỗi bộ chọn duy nhất phải có giá trị
    cat example/test.html | html-to-text > test.txt
    
    4 đượ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. Trận đấu tốt nhất được sử dụng thay thế (đó là lần cuối cùng 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 so với các bộ chọn được cung cấp, chúng được biên dịch thành cây quyết định. Nhưng nó cũng quan trọng như thế nào bạn chọn bộ chọn. Ví dụ: baseElements.selectors2 tốt hơn nhiều so với baseElements.selectors3 - cái trước sẽ chỉ kiểm tra các div cho ID trong khi cái sau phải kiểm tra mọi phần tử trong DOM.

Bộ chọn được hỗ trợ

html-to-text dựa vào các gói Parseley và Selderee cho 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:

  • baseElements.selectors5 - Bộ chọn phổ quát;
  • baseElements.selectors6 - tên thẻ;
  • baseElements.selectors7 - Tên lớp;
  • baseElements.selectors8 - ID;
  • baseElements.selectors9 - sự hiện diện thuộc tính;
  • 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
    00 - Giá trị thuộc tính (với bất kỳ toán tử nào và cả trích dẫn và các sửa đổi độ nhạy trường hợp);
  • 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
    01 và
    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
    02 Combinators (các tổ hợp khác không được hỗ trợ).

Bạn có thể khớp

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
03 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 World
04 chẳng hạn.

Định dạng được xác định trước

Các bộ chọn sau có một định dạng được chỉ định là một phần của cấu hình mặc định. Mọi thứ có thể bị ghi đè, nhưng bạn không phải lặp lại

cat example/test.html | html-to-text > test.txt
4 hoặc các tùy chọn mà bạn không muốn ghi đè. (Nhưng hãy nhớ đ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.)

Bộ chọnDefault formatGhi chú
baseElements.selectors5
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
07
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 World
08
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 { 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
10
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
11
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
12
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
11
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
12
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
12
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
14
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
16
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
17
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
11
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
12
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
11
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
12
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
11
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
12
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
14
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
12
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
14
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
16
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
14
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
16
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
14
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
16
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
14
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
16
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
14
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
16
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
11
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
12
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
14
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
16
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
17
baseElements.selectors6
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
11
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
12
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
11
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
12
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
14
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
16
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
17
baseElements.selectors6baseElements.selectors6
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
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 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 World
22
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
24
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
25
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
28
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
28

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
30

  • 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
    32
  • 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
    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 World
38

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
39
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
40
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 World
41
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
42
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
44
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
46
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
47
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 World
48
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
49
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
46
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
47
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 World
48
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
49
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
50
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
52
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 World
76 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 World
77 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 World
78.
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 World
69 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 World
75.
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 World
11. 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 World
55 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 World
56
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
50
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
52
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 World
86 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 World
11. 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 World
55 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 World
56
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 { 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
10
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
90 => 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 World
91.
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 World
7 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 World
93 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 World
94 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 World
95 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 World
94 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 World
11
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
56
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 { 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
10
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
11
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
12
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 { 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
10
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
11
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
12
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
25
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
28
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
30
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
12
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
14
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
16
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 World
17
baseElements.selectors6
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
14
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
16
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
17
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
12
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
12
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
14
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 World
7
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
55
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 World
55
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 World
55
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 World
55
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 toDepr.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 World
65
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
  • cat example/test.html | html-to-text --tables=#invoice,.address --wordwrap=100 > test.txt
    
    9
  • 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ụ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!
    // こんにちは世界!
    // Привет, мир!
    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ụng html-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-text8 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.