src/Truncate.js
// Shim innerText to consistently break lines at <br/> but not at \n
Shim innerText to consistently break lines at  but not at \n
Shim innerText to consistently break lines at but not at \ n
innerText(node) {
        const div = document.createElement('div');
        const contentKey = 'innerText' in window.HTMLElement.prototype ? 'innerText' : 'textContent';
        div.innerHTML = node.innerHTML.replace(/\r\n|\r|\n/g, ' ');
        let text = div[contentKey];
        const test = document.createElement('div');
        test.innerHTML = 'foo<br/>bar';
        if (test[contentKey].replace(/\r\n|\r/g, '\n') !== 'foo\nbar') {
            div.innerHTML = div.innerHTML.replace(/<br.*?[\/]?>/gi, '\n');
            text = div[contentKey];
        }
        return text;
    }
innerText ( node ) { const div = document . createElement ( 'div' ) ; const contentKey = 'innerText' in window . HTMLElement . prototype ? 'innerText' : 'textContent' ; div . innerHTML = node . innerHTML . replace ( / \r\n|\r|\n / g , ' ' ) ; let text = div [ contentKey ] ; const test = document . createElement ( 'div' ) ; test . innerHTML = 'foo<br/>bar' ; if ( test [ contentKey ] . replace ( / \r\n|\r / g , '\n' ) !== 'foo\nbar' ) { div . innerHTML = div . innerHTML . replace ( / <br.*?[\/]?> / gi , '\n' ) ; text = div [ contentKey ] ; } return text ; }
Shim innerText to consistently break lines at <br/> but not at \n
Shim innerText to consistently break lines at <br / > but not at \ n