Comments (9)
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.
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.
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.
Yes!
from anglesharp.
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.
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.
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.
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.
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)
- Request for Support / Sponsorship HOT 1
- IHtmlDocument has IDisposable - for what?) HOT 1
- Redirect to Custom URL Scheme HOT 2
- Issues with Headers HOT 2
- Use libraries provided by framework HOT 3
- Provide repo link as part of nuget package HOT 8
- QuerySelectorAll problem HOT 1
- SemVer scheme in AngleSharp -alpha versions broken HOT 1
- Multipart/form-data support HOT 1
- IndexOutOfRangeException in AngleSharp.Common.ArrayPoolBuffer.Append HOT 1
- Getting Attributes for each Element HOT 1
- InvalidOperationException: Stack empty in AngleSharp.Html.Parser.HtmlDomBuilder HOT 1
- Attributes in Elements HOT 3
- Parser Issue Findings from Fuzzing HOT 4
- Additional Findings from Fuzzing HOT 3
- NullReferenceException when using own HttpClient HOT 1
- How to Change the Accept header in DocumentRequest HOT 1
- Link element source not loaded when element is appended to document
- AngleSharp 1.2.0-beta.410 can not be loaded in .Net Framework because of System.Memory version error HOT 3
- obsolete reference HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anglesharp.