node-html-to-text
node-html-to-text copied to clipboard
Anchor sub elements and support for placeholders, fragments, and HTML4 name
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
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 attributeinner- process the child elementsappendorprepend- put the link in brackets[]before or after the sub element text representation- Function - Add your own formatting behaviour.
What do you mean?
it will fix the "href missing bug" too !
I currently don't have the time or the need to resolve this issue. Push requests are welcome ;)