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.selectorsconst { 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 World0Elemen 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 World1const { 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 World2const { 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 World2 - 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 World5 - 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 World6const { 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 World7Konversi 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 World8const { 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 World7Mendekode 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 World7. 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! // こんにちは世界! // Привет, мир!1const { 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! // こんにちは世界! // Привет, мир!3const { 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! // こんにちは世界! // Привет, мир!6const { 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! // こんにちは世界! // Привет, мир!8const { 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: '//example.com' } }, { selector: 'a.button', format: 'skip' } ] }); console.log(text); // Page [//example.com/page.html]0const { 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: '//example.com' } }, { selector: 'a.button', format: 'skip' } ] }); console.log(text); // Page [//example.com/page.html]2const { 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: '//example.com' } }, { selector: 'a.button', format: 'skip' } ] }); console.log(text); // Page [//example.com/page.html]4const { 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: '//example.com' } }, { selector: 'a.button', format: 'skip' } ] }); console.log(text); // Page [//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: '//example.com' } }, { selector: 'a.button', format: 'skip' } ] }); console.log(text); // Page [//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: '//example.com' } }, { selector: 'a.button', format: 'skip' } ] }); console.log(text); // Page [//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: '//example.com' } }, { selector: 'a.button', format: 'skip' } ] }); console.log(text); // Page [//example.com/page.html]8const { 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: '//example.com' } }, { selector: 'a.button', format: 'skip' } ] }); console.log(text); // Page [//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!0const { 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!2const { 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!6const { 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: '//example.com' } }, { selector: 'a.button', format: 'skip' } ] }); console.log(text); // Page [//example.com/page.html]9Menjelaskan bagaimana elemen HTML yang berbeda harus diformat. Lihat bagian di bawah ini. ________32______8const { 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);0import { 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, gunakanimport { 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________42const { 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 World8. 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. 0const 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 } } ], // ... }1const 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. 0const 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. 0const 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 } } ], // ... }5const 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. 0const 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. 0const 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. 0const 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: '//example.com' } }, { selector: 'a.button', format: 'skip' } ] }); console.log(text); // Page [//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 World08 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 World09 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 World10 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 formatNotesconst { 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 World01const { 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 World13Universal 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 World14const { 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 World15const { 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 World16const { 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 World17const { 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 World18const { 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 World17const { 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 World20const { 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 World20const { 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 World22const { 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 World23const { 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 World02const { 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 World17const { 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 World26const { 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 World17const { 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 World28const { 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 World17const { 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 World30const { 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 World31const { 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 World32const { 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 World31const { 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 World34const { 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 World31const { 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 World36const { 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 World31const { 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 World38const { 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 World31const { 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 World40const { 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 World31const { 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 World42const { 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 World17const { 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 World44const { 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 World45const { 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 World46const { 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 World47const { 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 World48const { 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 World17const { 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 World50const { 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 World17const { 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 World52const { 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 World53const { 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 World54const { 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 World55const { 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 World56const { 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 World56const { 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 World58const { 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 World58Equivalent 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 World17. 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_62const { 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 World63const { 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 World64const { 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 World64

Lebih banyak pemformat juga tersedia untuk digunakan

FormatDescriptionconst { 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 World69) 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 World71Render 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 World69) 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 World75 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 World76). 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 World78Render elemen dengan semua turunannya sebagai HTML sebarisOpsi format

Opsi berikut tersedia untuk pemformat bawaan

OptionDefaultApplies toDescriptionconst { 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 World79const { 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 World80, 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 World81 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 World82semua 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 World83const { 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 World80 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 World81semua 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 World86import { 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);2const { 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 World15, 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 World47Host 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 World90 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 World91 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 World92)
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 World93 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 World94 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 World95. 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_96const { 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 World97const { 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 World15, 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 World47Tautan 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! // こんにちは世界! // Привет, мир!02const { 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! // こんにちは世界! // Привет, мир!9const { 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 World15, 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 World47A 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 World90 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 World91 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 } } ], // ... }0const { 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!1const { 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 World15 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 } } ], // ... }2const { 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!1const { 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 World15Ignore all links. Hanya memproses teks internal tag jangkar. html-to-text1const { 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 World7const { 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 World15Abaikan 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! // こんにちは世界! // Привет, мир!26const { 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! // こんにちは世界! // Привет, мир!27const { 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 World63Awalan 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! // こんにちは世界! // Привет, мир!29const { 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 World7const { 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 World31Secara 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! // こんにちは世界! // Привет, мир!35const { 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! // こんにちは世界! // Привет, мир!9const { 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 World45Length 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! // こんにちは世界! // Привет, мир!39const { 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 World7const { 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 World20Potong 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! // こんにちは世界! // Привет, мир!42const { 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 World7const { 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 World61Secara 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! // こんにちは世界! // Привет, мир!47const { 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! // こんにちは世界! // Привет, мир!48const { 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 World61Konten 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! // こんにちは世界! // Привет, мир!53const { 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 World82const { 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 World61Jumlah 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! // こんにちは世界! // Привет, мир!56const { 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! // こんにちは世界! // Привет, мир!57const { 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 World61Jumlah 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! // こんにちは世界! // Привет, мир!59const { 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! // こんにちは世界! // Привет, мир!60const { 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 World68, 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 World72Sebuah 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! // こんにちは世界! // Привет, мир!63const { 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! // こんにちは世界! // Привет, мир!60const { 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 World74String 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! // こんにちは世界! // Привет, мир!66const { 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! // こんにちは世界! // Привет, мир!60const { 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 World74Suffix string yang akan dimasukkan setelah isi tag inlineOpsi format yang tidak digunakan lagiOpsi lamaBerlaku untukDepr. Rem. Sebagai gantinya gunakanhtml-to-text3const { 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 World158. 1const { 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.

Postingan terbaru

LIHAT SEMUA