Bagaimana Anda menulis teks hanya dalam html?

Versi 8 menghadirkan dukungan penyeleksi untuk meningkatkan fleksibilitas tetapi itu juga mengubah beberapa hal yang diperkenalkan di versi 6. Pemilihan elemen dasar juga mendapat perubahan penting

Versi 9 menghapus banyak opsi yang sebelumnya tidak digunakan lagi, memperkenalkan beberapa pemformat baru dan kemampuan baru untuk pemformat kustom. Sekarang paket mode ganda (cjs dan esm). CLI dipindahkan ke paket terpisah

Instalasi

npm install html-to-text

Penggunaan

Mengonversi satu dokumen

const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
_

Konfigurasikan html-to-text satu kali untuk pemrosesan batch (disarankan untuk kinerja yang baik)

const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!

Pilihan

Pilihan umum

OptionDefaultDescriptionbaseElementsMenjelaskan bagian mana dari dokumen masukan yang harus diubah dan ditampilkan dalam teks keluaran, dan dalam urutan apa. baseElements.selectors
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
0Elemen yang cocok dengan salah satu pemilih yang disediakan akan diproses dan disertakan dalam teks keluaran, dengan semua konten dalamnya
Lihat bagian di bawah ini.
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
2 - mengatur elemen dasar dalam urutan yang sama seperti baseElements.selectors array;
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
5 - mengatur elemen dasar dalam urutan yang ditemukan dalam dokumen masukan.
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
7Konversi seluruh dokumen jika tidak ada pemilih yang cocok.
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
7Mendekode entitas HTML yang ditemukan di input HTML jika
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
7. Kalau tidak, pertahankan dalam teks keluaran.
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
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 = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
2Kamus dengan karakter yang harus diganti dalam teks keluaran dan escape sequence yang sesuai.
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
3
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
2Objek dengan fungsi pemformatan khusus untuk elemen tertentu (lihat bagian di bawah).
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
5Menjelaskan cara membatasi teks keluaran jika dokumen HTML berukuran besar.
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
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 = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
7Sebuah string untuk disisipkan sebagai pengganti konten yang dilewati.
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
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 = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
9Berhenti mencari lebih banyak elemen dasar setelah mencapai jumlah ini. Tidak terbatas jika tidak ditentukan.
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
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
9Jumlah maksimum node anak dari satu node yang akan ditambahkan ke output. Tidak terbatas jika tidak ditentukan.
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 { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
9Berhenti mencari node untuk ditambahkan ke output di bawah kedalaman ini di pohon DOM. Tidak terbatas jika tidak ditentukan.
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
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]
5Jika string input lebih panjang dari nilai ini - itu akan dipotong dan pesan akan dikirim ke
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. Ellipsis tidak digunakan dalam kasus ini. Tidak terbatas jika tidak ditentukan.
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]
7Menjelaskan cara merangkai kata yang panjang.
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]
9Array yang berisi karakter yang dapat dibungkus. Diperiksa secara berurutan, pencarian berhenti setelah persyaratan panjang baris dapat dipenuhi.
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
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!
1Hilangkan kata-kata panjang pada batas panjang garis jika tidak ada peluang bungkus yang lebih baik ditemukan.
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
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!
1Secara default, setiap baris baru
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 dari input HTML diciutkan menjadi spasi seperti karakter spasi putih HTML lainnya. Jika
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
_7, baris baru ini akan dipertahankan dalam output. Ini hanya berguna ketika input HTML membawa beberapa pemformatan teks biasa alih-alih tag yang tepat.
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
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]
9Menjelaskan bagaimana elemen HTML yang berbeda harus diformat. Lihat bagian di bawah ini. ________32______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!
9Serangkaian karakter yang dikenali sebagai spasi putih HTML. Nilai default menggunakan kumpulan karakter yang ditentukan di. (Ini termasuk ruang dengan lebar nol dibandingkan dengan. )
import { compile, convert } from 'html-to-text';

// for batch use:
const compiledConvert = compile(options);
let text = compiledConvert(html, metadata);

// for single use:
let text = convert(html, options, metadata);
0
import { compile, convert } from 'html-to-text';

// for batch use:
const compiledConvert = compile(options);
let text = compiledConvert(html, metadata);

// for single use:
let text = convert(html, options, metadata);
1Setelah berapa banyak karakter, jeda baris harus diikuti
Setel ke
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 atau
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!
1 untuk menonaktifkan pembungkusan kata

Opsi yang tidak digunakan lagi atau dihapus

Opsi lamaDepr. Rem. Sebagai gantinya, gunakan
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________42
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
_42_______69. Decoding 0Entitas sekarang ditangani oleh htmlparser2 sendiri dan entitas secara internal. Tidak ada bagian yang dapat dikonfigurasi pengguna dibandingkan dengan dia selain boolean
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
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. 0Cara formatter ditulis telah berubah total. Pemformat baru harus ditambahkan ke opsi
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
_3, yang lama tidak dapat digunakan kembali tanpa menulis ulang. Lihat di bawah.
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
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 }
    }
  ],
  // ...
}
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
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 }
    }
  ],
  // ...
}
3________52______46. 09. 0
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 }
    }
  ],
  // ...
}
5
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 }
    }
  ],
  // ...
}
66. 09. 0
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 }
    }
  ],
  // ...
}
_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. 0html-to-text2html-to-text36. 09. 0html-to-text4html-to-text58. 0html-to-text6html-to-text76. 09. 0
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 }
    }
  ],
  // ...
}
_7
html-to-text_9
baseElements_0
html-to-text0baseElements28. 0baseElements3baseElements48. 0Lihat bagian di bawah ini. baseElements_56. 09. 0baseElements6baseElements76. 09. 0
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 }
    }
  ],
  // ...
}
_7
baseElements_9
baseElements.selectors_0
baseElements.selectors_1
html-to-text0

Hal-hal lain dihapus

  • baseElements.selectors3 metode - gunakan baseElements.selectors4 atau baseElements.selectors5 sebagai gantinya;
  • argumen posisional dalam metode baseElements.selectors_6 - berikan objek opsi sebagai gantinya

Selektor

Beberapa contoh

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]

Selectors array adalah perkiraan stylesheet kami yang longgar

  • pemilih tertinggi digunakan saat ada beberapa kecocokan;
  • pemilih terakhir digunakan ketika ada banyak kecocokan dengan spesifisitas yang sama;
  • semua entri dengan nilai pemilih yang sama digabungkan (secara rekursif) pada tahap kompilasi, sedemikian rupa sehingga properti yang terakhir ditentukan disimpan dan urutan relatif dari pemilih unik disimpan;
  • entri yang ditentukan pengguna ditambahkan setelah ;
  • Setiap pemilih unik harus memiliki nilai
    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 yang ditentukan (setidaknya sekali);
  • tidak seperti di CSS, nilai dari pemilih yang cocok berbeda TIDAK digabungkan pada tahap konversi. Satu kecocokan terbaik digunakan sebagai gantinya (itu adalah yang terakhir dari yang memiliki kekhususan tertinggi)

Untuk mencapai performa terbaik saat memeriksa setiap elemen DOM terhadap pemilih yang disediakan, mereka dikompilasi ke dalam pohon keputusan. Tetapi juga penting bagaimana Anda memilih penyeleksi. Misalnya, baseElements.selectors_8 jauh lebih baik daripada baseElements.selectors9 - yang pertama hanya akan memeriksa div untuk id sementara yang terakhir harus memeriksa setiap elemen di DOM

Selektor yang didukung

_____ 246 _____ bergantung pada paket peterseli dan selderee untuk dukungan penyeleksi

Selektor berikut dapat digunakan dalam kombinasi apa pun

  • const { convert } = require('html-to-text');
    // There is also an alias to `convert` called `htmlToText`.
    
    const html = '<h1>Hello World</h1>';
    const text = convert(html, {
      wordwrap: 130
    });
    console.log(text); // Hello World
    _01 - pemilih universal;
  • const { convert } = require('html-to-text');
    // There is also an alias to `convert` called `htmlToText`.
    
    const html = '<h1>Hello World</h1>';
    const text = convert(html, {
      wordwrap: 130
    });
    console.log(text); // Hello World
    _02 - nama tag;
  • const { convert } = require('html-to-text');
    // There is also an alias to `convert` called `htmlToText`.
    
    const html = '<h1>Hello World</h1>';
    const text = convert(html, {
      wordwrap: 130
    });
    console.log(text); // Hello World
    _03 - nama kelas;
  • const { convert } = require('html-to-text');
    // There is also an alias to `convert` called `htmlToText`.
    
    const html = '<h1>Hello World</h1>';
    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 = '<h1>Hello World</h1>';
    const text = convert(html, {
      wordwrap: 130
    });
    console.log(text); // Hello World
    _05 - kehadiran atribut;
  • const { convert } = require('html-to-text');
    // There is also an alias to `convert` called `htmlToText`.
    
    const html = '<h1>Hello World</h1>';
    const text = convert(html, {
      wordwrap: 130
    });
    console.log(text); // Hello World
    _06 - nilai atribut (dengan operator apa pun dan juga kutipan dan pengubah sensitivitas huruf besar-kecil);
  • const { convert } = require('html-to-text');
    // There is also an alias to `convert` called `htmlToText`.
    
    const html = '<h1>Hello World</h1>';
    const text = convert(html, {
      wordwrap: 130
    });
    console.log(text); // Hello World
    _07 dan
    const { convert } = require('html-to-text');
    // There is also an alias to `convert` called `htmlToText`.
    
    const html = '<h1>Hello World</h1>';
    const text = convert(html, {
      wordwrap: 130
    });
    console.log(text); // Hello World
    08 kombinator (kombinator lain tidak didukung)

Anda dapat mencocokkan

const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
09 dengan
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
10 misalnya

Pemformat yang telah ditentukan sebelumnya

Pemilih berikut memiliki pemformat yang ditentukan sebagai bagian dari konfigurasi default. Semuanya dapat ditimpa, tetapi Anda tidak perlu mengulangi

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 atau opsi yang tidak ingin Anda timpa. (Namun perlu diingat ini hanya berlaku untuk pemilih yang sama. Tidak ada koneksi antara pemilih yang berbeda. )

SelectorDefault formatNotes
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
17. Gunakan
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
_61 sebagai gantinya untuk data tabular.
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

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

Lebih banyak pemformat juga tersedia untuk digunakan

FormatDescription
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
_61Untuk tabel yang akurat secara visual. Perhatikan bahwa ini mungkin tidak ramah pencarian (teks keluaran akan terlihat seperti omong kosong untuk mesin ketika ada konten sel yang dibungkus) dan juga sebaiknya dihindari untuk tabel yang digunakan sebagai alat tata letak halaman.
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
_67Lewati tag yang diberikan dengan isinya tanpa mencetak apa pun.
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
_68Sisipkan blok dengan string literal yang diberikan (
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
69) alih-alih tag.
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
_70Render elemen sebagai tas blok HTML, ubah isinya menjadi teks.
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
71Render elemen dengan semua turunannya sebagai blok HTML.
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
_72Masukkan literal string yang diberikan (
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
69) sebaris alih-alih tag.
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
_74Render elemen sebaris dibungkus dengan string yang diberikan (
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
75 dan
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
_77Render elemen sebagai tag HTML sebaris, ubah isinya menjadi teks.
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
78Render elemen dengan semua turunannya sebagai HTML sebaris
Opsi format

Opsi berikut tersedia untuk pemformat bawaan

OptionDefaultApplies toDescription
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
81 atau
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
82semua pemformat tingkat blokJumlah jeda baris untuk memisahkan blok sebelumnya dari blok ini
Perhatikan bahwa jeda baris N+1 diperlukan untuk membuat N baris kosong.
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
80 atau
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
81semua pemformat tingkat blokJumlah jeda baris untuk memisahkan blok ini dari yang berikutnya
Perhatikan bahwa jeda baris N+1 diperlukan untuk membuat N baris kosong.
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
47Host server untuk tautan
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
90 atribut dan gambar
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
91 atribut relatif terhadap root (yang dimulai dengan
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
92)
Misalnya, dengan
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
93 dan
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
94 tautan dalam teks akan menjadi
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
47Tautan keliling dengan tanda kurung ini
Setel ke
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!
1 atau
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
01 untuk menonaktifkan.
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
02
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
47A berfungsi untuk menulis ulang tautan
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
90 atribut dan gambar
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
91 atribut. Argumen kedua opsional adalah objek metadata
Diterapkan sebelum
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
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 = '<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!
1
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
15 Secara default tautan diterjemahkan dengan cara berikut
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
12 => menjadi =>
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
13
Jika opsi ini disetel ke
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
_7 dan
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
15 dan
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
16 sama,
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
17 akan dihilangkan dan hanya
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
16 yang akan ada.
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 = '<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!
1
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
15Ignore all links. Hanya memproses teks internal tag jangkar. html-to-text1
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
15Abaikan tautan jangkar (di mana
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
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 = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
26
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
27
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
63Awalan string untuk setiap item daftar.
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
29
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
31Secara default, judul (
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
32,
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
33, dll) menggunakan huruf besar
Setel ini ke
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!
_1 untuk membiarkan heading apa adanya.
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
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 = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
45Length of the line. Jika tidak ditentukan maka nilai
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 digunakan. Jatuh kembali ke 40 jika itu juga dinonaktifkan.
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
39
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
20Potong baris kosong dari blockquote
Sementara baris kosong harus dipertahankan dalam HTML, perilaku hemat ruang dipilih sebagai default untuk kenyamanan.
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
42
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
61Secara default, sel heading (
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
45) menggunakan huruf besar
Setel ini ke
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!
_1 untuk membiarkan sel judul sebagaimana adanya.
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
47
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
48
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
61Konten sel tabel data akan dibungkus agar sesuai dengan lebar ini, bukan batas
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 global
Tetapkan ini ke
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
_9 untuk kembali ke batas
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 = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
61Jumlah spasi antara kolom tabel data.
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
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 = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
61Jumlah baris kosong antara baris tabel data.
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
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 = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
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 = '<h1>Hello World</h1>';
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
72Sebuah string yang akan dimasukkan sebagai pengganti tag.
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
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 = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
74String awalan untuk dimasukkan sebelum isi tag inline.
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
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 = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
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 = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
74Suffix string yang akan dimasukkan setelah isi tag inline
Opsi format yang tidak digunakan lagi
Opsi lamaBerlaku untukDepr. Rem. Sebagai gantinya gunakanhtml-to-text3
const { convert } = require('html-to-text');
// There is also an alias to `convert` called `htmlToText`.

const html = '<h1>Hello World</h1>';
const text = convert(html, {
  wordwrap: 130
});
console.log(text); // Hello World
158. 1
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
_71

Ganti pemformatan

const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
3 opsi adalah objek yang memiliki fungsi pemformatan. Mereka dapat ditugaskan untuk memformat elemen yang berbeda dalam larik
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

Setiap pemformat adalah fungsi dari empat argumen yang tidak mengembalikan apa pun. Argumen adalah

  • const { compile } = require('html-to-text');
    
    const convert = compile({
      wordwrap: 130
    });
    
    const htmls = [
      '<h1>Hello World!</h1>',
      '<h1>こんにちは世界!</h1>',
      '<h1>Привет, мир!</h1>'
    ];
    const texts = htmls.map(convert);
    console.log(texts.join('\n'));
    // Hello World!
    // こんにちは世界!
    // Привет, мир!
    74 - elemen HTML yang akan diproses oleh pemformat ini;
  • const { compile } = require('html-to-text');
    
    const convert = compile({
      wordwrap: 130
    });
    
    const htmls = [
      '<h1>Hello World!</h1>',
      '<h1>こんにちは世界!</h1>',
      '<h1>Привет, мир!</h1>'
    ];
    const texts = htmls.map(convert);
    console.log(texts.join('\n'));
    // Hello World!
    // こんにちは世界!
    // Привет, мир!
    75 - fungsi rekursif untuk memproses anak-anak dari elemen ini. Disebut sebagai
    const { compile } = require('html-to-text');
    
    const convert = compile({
      wordwrap: 130
    });
    
    const htmls = [
      '<h1>Hello World!</h1>',
      '<h1>こんにちは世界!</h1>',
      '<h1>Привет, мир!</h1>'
    ];
    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 = [
      '<h1>Hello World!</h1>',
      '<h1>こんにちは世界!</h1>',
      '<h1>Привет, мир!</h1>'
    ];
    const texts = htmls.map(convert);
    console.log(texts.join('\n'));
    // Hello World!
    // こんにちは世界!
    // Привет, мир!
    77 - objek BlockTextBuilder. Memanipulasi status objek ini untuk membuat teks keluaran;
  • const { compile } = require('html-to-text');
    
    const convert = compile({
      wordwrap: 130
    });
    
    const htmls = [
      '<h1>Hello World!</h1>',
      '<h1>こんにちは世界!</h1>',
      '<h1>Привет, мир!</h1>'
    ];
    const texts = htmls.map(convert);
    console.log(texts.join('\n'));
    // Hello World!
    // こんにちは世界!
    // Привет, мир!
    78 - opsi yang ditentukan untuk tag, bersama dengan pemformat ini (Catatan. jika Anda memerlukan html-ke-teks umum - dapat diakses melalui
    const { compile } = require('html-to-text');
    
    const convert = compile({
      wordwrap: 130
    });
    
    const htmls = [
      '<h1>Hello World!</h1>',
      '<h1>こんにちは世界!</h1>',
      '<h1>Привет, мир!</h1>'
    ];
    const texts = htmls.map(convert);
    console.log(texts.join('\n'));
    // Hello World!
    // こんにちは世界!
    // Привет, мир!
    79)

Contoh pemformat kustom

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!

Baru di versi 9. objek metadata dapat disediakan sebagai argumen opsional terakhir dari fungsi baseElements.selectors4 (atau fungsi yang dikembalikan oleh fungsi

const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
81). Itu dapat diakses oleh pemformat sebagai
const { compile } = require('html-to-text');

const convert = compile({
  wordwrap: 130
});

const htmls = [
  '<h1>Hello World!</h1>',
  '<h1>こんにちは世界!</h1>',
  '<h1>Привет, мир!</h1>'
];
const texts = htmls.map(convert);
console.log(texts.join('\n'));
// Hello World!
// こんにちは世界!
// Привет, мир!
82

Lihat pemformat generik paket dasar dan pemformat teks paket ini untuk contoh lainnya. Cara termudah untuk menulis sendiri adalah memilih yang sudah ada dan menyesuaikannya

Lihat BlockTextBuilder untuk fungsi dan argumen yang tersedia

Metadata khusus

Jika Anda perlu memberikan informasi tambahan tentang dokumen HTML Anda untuk digunakan dalam pemformat khusus - ini dapat dilakukan dengan bantuan objek metadata

Bagaimana cara menulis teks dalam HTML?

HTML berisi beberapa elemen untuk mendefinisikan teks dengan arti khusus. .
- Teks tebal
- Teks penting
- Teks miring
- Teks yang ditekankan
- Teks yang ditandai
- Teks lebih kecil
- Teks yang dihapus
- Teks yang disisipkan

Tag HTML mana yang digunakan untuk teks?

Grup Tag Teks adalah grup tag yang digunakan untuk membuat dokumen teks berformat baik. Tag teks mencakup

-

,

,
, , , , dan .

Bagaimana cara membatasi input dalam HTML?

The defines a field for entering a number. .
max - menentukan nilai maksimum yang diperbolehkan
min - menentukan nilai minimum yang diperbolehkan
langkah - menentukan interval nomor hukum
nilai - Menentukan nilai default

Bagaimana cara menyusun teks dalam HTML?

Dalam tag awal, spasi putih dan atribut diperbolehkan antara nama elemen dan pembatas penutup . Atribut terdiri dari nama, tanda sama dengan, dan nilai. Spasi putih diperbolehkan di sekitar tanda sama dengan.