node-html-to-text icon indicating copy to clipboard operation
node-html-to-text copied to clipboard

Can support css rules?

Open eromoe opened this issue 8 years ago • 1 comments

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.

eromoe avatar Sep 22 '17 07:09 eromoe

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.

KillyMXI avatar Jun 09 '21 15:06 KillyMXI