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

Anchor sub elements and support for placeholders, fragments, and HTML4 name

Open benjaminma opened this issue 12 years ago • 3 comments

Suggested anchor handling:

  • <a href="mailto:address"> - keep address
  • <a href="#fragment"> - process sub elements
  • <a href="url"> - keep url, process sub elements
  • <a name="id"> - process sub elements
  • <a> - process sub elements

benjaminma avatar Jul 11 '13 23:07 benjaminma

I agree with <a href="mailto:address">, <a name="id"> and <a>. <a href="#fragment"> depends on if you have links like "Jump to Foo" or not. The same applies to <a href="url">.

I think even for the mailto option other people want another behaviour. I think the best approuch would be to use your defaults and make them avaibale via options parameters. Something like this:

var text = htmlToText.fromString('<h1>Hello World</h1>', {
    format: {
        a: {
            mailTo: 'value' // 'append', 'prepend', 'inner' or supply a Function,
            url: 'append',
            fragment: 'inner',
            name: 'inner',
            none: 'inner'
         } // Replace this by a Function and handle all link types by your own
    }
});

These are the default options. I wrapped it in an format option so it is extensable (maybe for all tags in the future).

Following behaviour per value:

  • value - use the value inside the attribute
  • inner - process the child elements
  • append or prepend - put the link in brackets [] before or after the sub element text representation
  • Function - Add your own formatting behaviour.

What do you mean?

mlegenhausen avatar Jul 15 '13 09:07 mlegenhausen

it will fix the "href missing bug" too !

otopsy avatar Sep 16 '13 12:09 otopsy

I currently don't have the time or the need to resolve this issue. Push requests are welcome ;)

mlegenhausen avatar Sep 16 '13 21:09 mlegenhausen