JavaScript chuyển Html sang chuỗi

Xin chào Kevin,

Như nó có thể. Bạn có thể sử dụng đoạn mã như dưới đây

var gr = new GlideRecord('task');
gr.get('sys_id');
var htmlDesc = gr.description.getDisplayValue();
var txtDesc = htmlDesc.replace(/<(?:.|\n)*?>/gm, '');
gs.print(txtDesc);

Để có thêm tài liệu tham khảo, hãy kiểm tra liên kết do Albert đề xuất và kiểm tra thêm liên kết

Phiên bản 8 mang đến sự hỗ trợ của bộ chọn để 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 (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_______248_______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 = '

Hello World

'
; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World
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 trong
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 = '

Hello World

'
; 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 = '

Hello World

'
; 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 = '

Hello World

'
; 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ự như mảng baseElements.selectors;
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
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.
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
6
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
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.
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
8
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
7Giải mã các thực thể HTML được tìm thấy trong HTML đầu vào nếu
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
7. Nếu không thì giữ nguyên trong văn bản đầu ra.
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! // こんにちは世界! // Привет, мир!
1_______3_______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.
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! // こんにちは世界! // Привет, мир!
3_______3_______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).
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! // こんにちは世界! // Привет, мир!
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.
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! // こんにちは世界! // Привет, мир!
6
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! // こんにちは世界! // Привет, мир!
7Một chuỗi để chèn vào vị trí của nội dung bị bỏ qua.
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! // こんにちは世界! // Привет, мир!
8
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! // こんにちは世界! // Привет, мир!
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.
const { convert } = require('html-to-text');

const html = 'PageAction';
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_______3_______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: 'https://example.com' } },
    { selector: 'a.button', format: 'skip' }
  ]
});
console.log(text); // Page [https://example.com/page.html]
2_______3_______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: 'https://example.com' } },
    { selector: 'a.button', format: 'skip' }
  ]
});
console.log(text); // Page [https://example.com/page.html]
4
const { convert } = require('html-to-text');

const html = 'PageAction';
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]
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: 'https://example.com' } },
    { selector: 'a.button', format: 'skip' }
  ]
});
console.log(text); // Page [https://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: 'https://example.com' } },
    { selector: 'a.button', format: 'skip' }
  ]
});
console.log(text); // Page [https://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: '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 = 'PageAction';
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]
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_______33_______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_______33_______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 = '

Hello World

'
; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World
7, những dòng mới này sẽ được giữ nguyê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 thuần túy thay vì các thẻ thích hợp.
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_______23_______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. )______43_______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
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);
48. 0____43_______5
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);
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 = '

Hello World

'
; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World
8.
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 = [
  '

Hello World!

'
, '

こんにちは世界!

'
, '

Привет, мир!

'
]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!
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.
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____53_______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____53_______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____53_______5_______53_______66. 09. 0____53_______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-text0html-to-text16. 09. 0____247_______2html-to-text36. 09. 0____247_______4____247_______58. 0____247_______6_______247_______76. 09. 0____53_______7
html-to-text9
baseElements0
html-to-text0baseElements28. 0____248_______3_______248_______48. 0Xem phần bên dưới. baseElements56. 09. 0____248_______6baseElements76. 09. 0____53_______7
baseElements9
baseElements.selectors0
baseElements.selectors1
html-to-text0

Những thứ khác đã bị xóa

  • Phương pháp baseElements.selectors3 - thay vào đó hãy sử dụng baseElements.selectors4 hoặc baseElements.selectors5;
  • các đối số vị trí trong các phương thức baseElements.selectors6 - 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: 'https://example.com' } },
    { selector: 'a.button', format: 'skip' }
  ]
});
console.log(text); // Page [https://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.selectors8 tốt hơn nhiều so với baseElements.selectors9 - 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

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

_____ 247 _____ dựa vào 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 = '

    Hello World

    '
    ; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World
    01 - bộ chọn phổ quá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
    02 - thẻ tên;
  • 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
    03 - tên lớp;
  • 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
    04 - id;
  • 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
    05 - sự hiện diện của thuộc tính;
  • 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
    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);
  • Bộ kết hợp
    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
    07 và
    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
    08 (các bộ kết hợp khác không được hỗ trợ)

Ví dụ, bạn có thể ghép

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
09 với
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
10

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

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 = '

Hello World

'
; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World
01
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
13Universal selector.
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
14
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
15
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
16
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
17
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
18
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
17
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
20
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
20
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
22
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
23
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
02
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
17
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
26
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
17
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
28
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
17
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
30
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
31
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
32
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
31
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
34
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
31
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
36
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
31
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
38
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
31
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
40
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
31
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
42
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
17
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
44
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
45
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
46
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
47
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
48
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
17
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
50
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
17
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
52
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
53
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
54
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
55
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
56
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
56
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
58
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
58Equivalent to
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
17. Sử dụng
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
61 thay cho dữ liệu dạng bảng.
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
62
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
63
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
64
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
64

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 = '

Hello World

'
; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World
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.
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
67Bỏ qua thẻ đã cho với nội dung của nó mà không in bất cứ thứ gì.
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
68Chèn một khối với chuỗi ký tự đã cho (
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
69) thay vì thẻ.
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
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.
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
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.
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
72Chèn nội tuyến chuỗi ký tự đã cho (
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
69) thay vì thẻ.
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
74Kết xuất phần tử nội tuyến được bọc bằng các chuỗi đã cho (
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
75 và
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
76).
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
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.
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
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ến
Tùy chọn định dạng

Các tùy chọn sau có sẵn cho các trình định dạng tích hợp

OptionDefaultApplies toDescription
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
79
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
80,
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
81 hoặc
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
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ày
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 = '

Hello World

'
; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World
83
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
80 hoặc
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
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 theo
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 = '

Hello World

'
; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World
86
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 = '

Hello World

'
; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World
15,
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
47Máy chủ lưu trữ liên kế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
90 thuộc tính và hình ảnh
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
91 thuộc tính liên quan đến thư mục gốc (những thuộc tính bắt đầu bằng
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
92)
Ví dụ, với
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
93 và
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
94, liên kết trong văn bản sẽ là
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
95.
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
96
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
97
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
15,
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
47Liên kết bao quanh với các dấu ngoặc này
Đặ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 = [
  '

Hello World!

'
, '

こんにちは世界!

'
, '

Привет, мир!

'
]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!
01 để 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! // こんにちは世界! // Привет, мир!
02_______3_______9
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
15,
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
47Một chức năng để viết lại liên kế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
90 thuộc tính và hình ảnh
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
91 thuộc tính. Đối số thứ hai tùy chọn là đối tượng siêu dữ liệu
Áp dụng trước
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
86.
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 = '

Hello World

'
; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World
15Theo mặc định, các liên kết được dịch theo cách sau
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! // こんにちは世界! // Привет, мир!
12 => trở thành =>
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! // こんにちは世界! // Привет, мир!
13
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 = '

Hello World

'
; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World
7 và
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! // こんにちは世界! // Привет, мир!
15 và
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! // こんにちは世界! // Привет, мир!
16 giống nhau, thì
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! // こんにちは世界! // Привет, мир!
17 sẽ bị bỏ qua và chỉ có
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! // こんにちは世界! // Привет, мир!
16.
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 = '

Hello World

'
; const text = convert(html, { wordwrap: 130 }); console.log(text); // Hello World
15Ignore all links. Chỉ xử lý văn bản nội bộ của thẻ neo. html-to-text1
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
7
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
15Bỏ qua các liên kết neo (trong đó
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! // こんにちは世界! // Привет, мир!
25).
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! // こんにちは世界! // Привет, мир!
26_______3_______27____2_______63Chuỗi tiền tố cho mỗi mục danh sách.
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! // こんにちは世界! // Привет, мир!
29_______2_______7
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
31Theo mặc định, các tiêu đề (_______3_______32,
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! // こんにちは世界! // Привет, мир!
33, v.v.) được viết hoa
Đặ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 = [
  '

Hello World!

'
, '

こんにちは世界!

'
, '

Привет, мир!

'
]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!
35
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! // こんにちは世界! // Привет, мир!
9
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
45Length of the line. Nếu không xác định thì 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);
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 = [
  '

Hello World!

'
, '

こんにちは世界!

'
, '

Привет, мир!

'
]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!
39_______2_______7
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
20Cắt các dòng trống khỏi blockquote
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 = [
  '

Hello World!

'
, '

こんにちは世界!

'
, '

Привет, мир!

'
]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!
42_______2_______7
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
61Theo mặc định, các ô tiêu đề (
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! // こんにちは世界! // Привет, мир!
45) được viết hoa
Đặ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 = [
  '

Hello World!

'
, '

こんにちは世界!

'
, '

Привет, мир!

'
]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!
47_______3_______48
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
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ầu của
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 = [
  '

Hello World!

'
, '

こんにちは世界!

'
, '

Привет, мир!

'
]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!
9 để giảm về giới hạn
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 = [
  '

Hello World!

'
, '

こんにちは世界!

'
, '

Привет, мир!

'
]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!
53
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
82
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
61Số khoảng cách giữa các cột trong bảng dữ liệu.
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! // こんにちは世界! // Привет, мир!
56
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! // こんにちは世界! // Привет, мир!
57
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
61Số dòng trống giữa các hàng của bảng dữ liệu.
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! // こんにちは世界! // Привет, мир!
59
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! // こんにちは世界! // Привет, мир!
60
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
68,
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
72Một chuỗi được chèn vào vị trí của thẻ.
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! // こんにちは世界! // Привет, мир!
63
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! // こんにちは世界! // Привет, мир!
60
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
74Tiền tố chuỗi được chèn trước nội dung thẻ nội tuyến.
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! // こんにちは世界! // Привет, мир!
66
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! // こんにちは世界! // Привет, мир!
60
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
74Hậu tố chuỗi sẽ được chèn sau nội dung thẻ nội tuyến
Tùy chọn định dạng không dùng nữa
Tùy chọn cũ Áp dụng cho Depr. Rem. Thay vào đó hãy sử dụnghtml-to-text3_______2_______158. 1____3_______71

ghi đè định dạng

Tùy chọn

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! // こんにちは世界! // Привет, мир!
3 là một đối tượng chứa các 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ả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!
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 = [
      '

    Hello World!

    '
    , '

    こんにちは世界!

    '
    , '

    Привет, мир!

    '
    ]; const texts = htmls.map(convert); console.log(texts.join('\n')); // Hello World! // こんにちは世界! // Привет, мир!
    74 - phần tử HTML được xử lý bởi trình định dạng này;
  • 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! // こんにちは世界! // Привет, мир!
    75 - hàm đệ quy để xử lý phần tử con của phần tử này. Được gọi là
    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! // こんにちは世界! // Привет, мир!
    76;
  • 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! // こんにちは世界! // Привет, мир!
    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;
  • 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! // こんにちは世界! // Привет, мир!
    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 qua
    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! // こんにちは世界! // Привет, мир!
    79)

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.selectors4 (hoặc hàm được trả về bởi hàm

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! // こんにちは世界! // Привет, мир!
81). Nó có thể được truy cập bởi các trình định dạng dưới dạng
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! // こんにちは世界! // Привет, мир!
82

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

Làm cách nào để chuyển đổi HTML thành chuỗi trong JavaScript?

JavaScript. Nhận toàn bộ tài liệu HTML dưới dạng chuỗi. Thuộc tính HTML bên trong HTML DOM . Thuộc tính này đặt/trả về nội dung HTML (HTML bên trong) của một phần tử. Giá trị tài sản. chữ. Nó chỉ định nội dung HTML của một phần tử.

Làm cách nào để chuyển đổi dữ liệu HTML thành chuỗi?

Tạo một phần tử giả và gán nó cho một biến. Chúng ta có thể trích xuất sau bằng cách sử dụng các đối tượng phần tử. Gán văn bản HTML cho InternalHTML của phần tử giả và chúng ta sẽ nhận được văn bản thuần túy từ các đối tượng phần tử văn bản

Làm cách nào để lấy văn bản từ HTML trong JavaScript?

Bạn có thể sử dụng cái này. var phần tử = tài liệu. getElementById('txt'); . văn bản bên trong. yếu tố.

Làm cách nào để chuyển đổi mã HTML thành JavaScript?

Chuyển đổi tệp HTML thành tệp Javascript .
Chuyển đổiHTMLToJs. java. Tạo một lớp Java để chuyển đổi tất cả mã HTML thành Javascript (. js) tập tin. .
đầu ra. js. Chạy chương trình Java ở trên, nó sẽ chuyển đổi “Test. html” thành “Đầu ra. tài liệu js”. .
kiểm tra nó. Tạo một tệp HTML và bao gồm “Đầu ra. js” để hiển thị