第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何實(shí)現(xiàn) Mozilla 的可讀性.js我的網(wǎng)站?

如何實(shí)現(xiàn) Mozilla 的可讀性.js我的網(wǎng)站?

慕的地6264312 2022-09-29 15:54:41
https://github.com/mozilla/readability(可讀性.js用于創(chuàng)建網(wǎng)頁(yè)的讀取視圖)如何實(shí)現(xiàn)可讀性.js此測(cè)試網(wǎng)頁(yè)的問(wèn)題是,可讀性.js刪除了本網(wǎng)站的元素,我想保留并留下那些應(yīng)該刪除的元素。我希望有人能幫助我。謝謝!是否有任何關(guān)于如何使用可讀性的文檔.js?<html><head><title>Reader View shows only the browser in reader view</title>    <script src="https://raw.githack.com/mozilla/readability/master/Readability.js"></script></head><body>Everything outside the main div tag vanishes in Reader View<br><img class="no-print" src="http://dummyimage.com/1024x100/000/ffffff&text=This+banner+should+vanish+in+print+view"><div>   <h1>H1 tags outside ot a p tag are hidden in reader view</h1>   <img class="no-print" src="http://dummyimage.com/1024x100/000/ffffff&text=This+banner+is resized+in+print+view">   <p> 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 123456789 123456</p></div></body>    <script>    var article = new Readability(document).parse();    </script></html>測(cè)試頁(yè)面的來(lái)源:優(yōu)化網(wǎng)站以在 Firefox 中顯示讀者視圖
查看完整描述

3 回答

?
元芳怎么了

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超7個(gè)贊

您可以將DOM純化和可讀性一起使用,就像他們?cè)谖臋n中提到的那樣 -


import { Readability } from '@mozilla/readability'

import DOMPurify from 'dompurify';


function readable(doc) {

  const reader = new Readability(doc)

  const article = reader.parse()

  return article

}


let cloneDoc = document.cloneNode(true)

let parsed = readable(cloneDoc)

const markup = DOMPurify.sanitize(parsed.content)

markup將是可讀內(nèi)容的 html 字符串。嘗試查看可用的屬性。console.log(parsed)


查看完整回答
反對(duì) 回復(fù) 2022-09-29
?
慕村9548890

TA貢獻(xiàn)1884條經(jīng)驗(yàn) 獲得超4個(gè)贊

你試過(guò)這個(gè)嗎?

從他們的github頁(yè)面:

“可讀性的解析()通過(guò)修改DOM來(lái)工作。這將刪除網(wǎng)頁(yè)中的某些元素。您可以通過(guò)在創(chuàng)建可讀性對(duì)象時(shí)傳遞文檔對(duì)象的克隆來(lái)避免這種情況。

var documentClone = document.cloneNode(true); 
var article = new Readability(documentClone).parse();

您可以創(chuàng)建 dom 對(duì)象的副本,這樣您就不會(huì)實(shí)際修改實(shí)際的 dom


查看完整回答
反對(duì) 回復(fù) 2022-09-29
?
拉風(fēng)的咖菲貓

TA貢獻(xiàn)1995條經(jīng)驗(yàn) 獲得超2個(gè)贊

好。。。。

    document.getElementById("body").innerHTML = "<font face='Calibri' size='4'> 
    <h1>"+article.title+"</h1>"+article.content;


查看完整回答
反對(duì) 回復(fù) 2022-09-29
  • 3 回答
  • 0 關(guān)注
  • 178 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)