Giter Club home page Giter Club logo

Comments (9)

FlorianRappl avatar FlorianRappl commented on July 30, 2024

Well, the DOM serialization is specified (hence fixed). However, we could now do two things. Either you call a method that takes options, which will do the serialization (well, this is somewhat flexible, but not as much as I would like), or there will be a visitor like pattern, where the user gets to choose what serialization he wants to take - and how he wants to deal with it.

from anglesharp.

FlorianRappl avatar FlorianRappl commented on July 30, 2024

I now provide another ToHtml method that takes any instance implementing the IMarkupFormatter. Right now there is just a single class implementing this interface, which is the HtmlMarkupFormatter. I will probably also provide a XHtmlMarkupFormatter and / or a XmlMarkupFormatter, but you can also use your own formatter if the existing ones don't fit your needs.

My guess is that this approach is flexible enough to fit all needs associated with node serialization. Let me know if you think something is still missing.

from anglesharp.

thorn0 avatar thorn0 commented on July 30, 2024

Thank you, looks great. There are cases when it's needed to format InnerHtml of an element. Would you consider adding ToHtml to INodeList to make it possible to write: element.ChildNodes.ToHtml(formatter)?

from anglesharp.

FlorianRappl avatar FlorianRappl commented on July 30, 2024

Yes!

from anglesharp.

thorn0 avatar thorn0 commented on July 30, 2024

It'd be easier to inherit from AngleSharp.Html.HtmlMarkupFormatter if its methods were virtual and weren't declared as an explicit interface implementation. I submitted #57.

from anglesharp.

FlorianRappl avatar FlorianRappl commented on July 30, 2024

That all is on purpose. Please FCoI. The class itself has no data members and is only a functional construct. It should be treated as such. The class is also only visible, that you can actually use its methods.

from anglesharp.

thorn0 avatar thorn0 commented on July 30, 2024

Got it. However, I have trouble with writing a formatter implementation for following requirements. Line breaks should be inserted before and after each block element (looking just at its name: p, div, etc.), but two consecutive line breaks must never be inserted.

For example:

<div>123</div>456<div>789</div><div>abc</div><ul><li>aa</li><li>bb</li></ul>

should be converted to

<div>123</div>
456
<div>789</div>
<div>abc</div>
<ul>
<li>aa</li>
<li>bb</li>
</ul>

TinyMCE formats HTML this way. The demo on the main page shows formatted HTML if you click _Tools -> Source code_. Just in case, here is their implementation.

from anglesharp.

thorn0 avatar thorn0 commented on July 30, 2024

I thought I implemented it, but suddenly it turned out that CloseTag for an element is called before the serialization of the children. :)

from anglesharp.

FlorianRappl avatar FlorianRappl commented on July 30, 2024

Yap, I call CloseTag before serializing the children. For me that was alright, but if you want to allow the scenario you are talking about, it should be called in logical order. I will fix this.

from anglesharp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.