zzzprojects / html-agility-pack

Html Agility Pack (HAP) is a free and open-source HTML parser written in C# to read/write DOM and supports plain XPATH or XSLT. It is a .NET code library that allows you to parse "out of the web" HTML files.
https://html-agility-pack.net
MIT License
2.62k stars 375 forks source link

Convert HTML to Text #566

Open TonyValenti opened 1 month ago

TonyValenti commented 1 month ago

Here is what to include in your request to make sure we implement a solution as quickly as possible.

1. Description

It would be really nice if there were a method I could use to convert HTML to text. This is not the same as Node.InnerText or HtmlEntity.DeEntitize

The goal is that HTML would be converted to text with line breaks that likely represents about what a user would see on the screen.

I propose using the following rules:

  1. <br> inserts a new line.
  2. Content after a </p> inserts two new lines.
  3. URLs generate text like: ` Text [Link]

Can you add something like this?

JonathanMagnan commented 1 month ago

Hello @TonyValenti ,

I don't know if we will add it, but we can certainly discuss it and see if it is worth it. In the worst case, it will become an extension method that you add to your project.

So here are a few questions. How would you treat:

I feel that perhaps we will end up using an HTML to Markdown converter

Best Regards,

Jon