node-html-to-text
node-html-to-text copied to clipboard
Can support css rules?
Hi,
I mean some site has their rule such as make a block , in this case, need a \n in text.
For example:
<div>
<p styles="display:inline">
inline 1 (no \n)
</p>
<p styles="display:inline">
inline 2 (no \n)
</p>
<p >
<a styles="display:block"> block 1(need add \n after) </a>
block 2(need add \n after)
</p>
</div>
But styles always not write with element, usually in css, it would be nice to load several .css files to precisely convert html to text.
Version 8 is now live.
It add a pretty good selectors support that allows to match on style attribute as well:
{
selectors: [
{ selector: 'p[style*="display:inline"i]', format: 'inline' },
{ selector: 'a[style*="display:block"i]', format: 'block' }
// might need a custom formatter in case a.href etc is needed
]
}
At this point it seems unlikely html-to-text will go as far as doing full cascade style sheets though.
HTML CSS is not really useful for text rendering in the most part - plain text medium is way too different.