Convert HTML to plain text in JS without browser environment

前端 未结 6 1361
孤街浪徒
孤街浪徒 2020-12-29 23:59

I have a CouchDB view map function that generates an abstract of a stored HTML document (first x characters of text). Unfortunately I have no browser environmen

6条回答
  •  粉色の甜心
    2020-12-30 00:31

    You can try this way. textContent with innerText neither of them compatible with all browsers:

    var temp = document.createElement("div");
    temp.innerHTML = html;
    return temp.textContent || temp.innerText || "";
    

提交回复
热议问题