Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node.OuterHtml Lose img element "/" #425

Closed
yuejunhi opened this issue Feb 22, 2021 · 8 comments
Closed

node.OuterHtml Lose img element "/" #425

yuejunhi opened this issue Feb 22, 2021 · 8 comments
Assignees

Comments

@yuejunhi
Copy link

1. Description

Create img HtmlNode
HtmlNode node = HtmlNode.CreateNode("<img src="123.jpg"/>");
Get the html string from the created node object:node.OuterHtml is equal "<img src="123.jpg">", lose “/”.
How to get complete html string "<img src="123.jpg"/>"?

@JonathanMagnan JonathanMagnan self-assigned this Feb 22, 2021
@JonathanMagnan
Copy link
Member

Hello @yuejunhi ,

This is by purpose since closing is invalid in HTML 5. See the following answer: https://stackoverflow.com/a/54412209

If you wish, we could check if that's possible to add an option to force the "close" which I believe will make sense for many people.

Just let us know if you need this option or not.

Best Regards,

Jon


Performance Libraries
context.BulkInsert(list, options => options.BatchSize = 1000);
Entity Framework ExtensionsEntity Framework ClassicBulk OperationsDapper Plus

Runtime Evaluation
Eval.Execute("x + y", new {x = 1, y = 2}); // return 3
C# Eval FunctionSQL Eval Function

@yuejunhi
Copy link
Author

yuejunhi commented Feb 22, 2021

Hello @JonathanMagnan ,

If you can add an option to force the "close",please like "<img src="123.jpg"/>".

Best Regards,

yue

@JonathanMagnan
Copy link
Member

Sure, we will look at it

@JonathanMagnan
Copy link
Member

Hello @yuejunhi ,

Look like we already have this options. See the following example:

HtmlDocument htmlDocument = new HtmlDocument();
htmlDocument.OptionWriteEmptyNodes = true;
htmlDocument.LoadHtml(@"<div><img src=""123.jpg"" />");
var test = htmlDocument.DocumentNode.OuterHtml;

Let me know if that's what you were looking for.

Best Regards,

Jon

@yuejunhi
Copy link
Author

yuejunhi commented Feb 23, 2021

Hello @JonathanMagnan ,

Could you override the method of “HtmlNode.CreateNode(string html)” ,like "HtmlNode.CreateNode(string html, bool OptionWriteEmptyNodes)”?
Let me set htmlDocument.OptionWriteEmpty value equal true or false!

Best Regards,

Yue

@JonathanMagnan
Copy link
Member

Oh I see,

I copied the code from my developer but that doesn't fit 100% for your requirement.

Sure, we will look at it.

@yuejunhi
Copy link
Author

Hello @JonathanMagnan ,

Please see the following example:
HtmlNode node = HtmlNode.CreateNode("<img src="123.jpg" />");
string htmlStr = node.OuterHtml;
The result "htmlStr",we want , is equal "<img src="123.jpg"/>",
but we get "<img src="123.jpg">" ,lose "/";
Could you override the method of “HtmlNode.CreateNode(string html)” ,like "HtmlNode.CreateNode(string html, bool OptionWriteEmptyNodes)”?
Let me set htmlDocument.OptionWriteEmpty value equal true or false!
Best Regards,

Yue

@JonathanMagnan
Copy link
Member

Hello @yuejunhi ,

The v1.11.31 has been released.

It's now possible to pass a builder to choose some options such as OptionWriteEmptyNodes

Here is an example:

HtmlNode node2 = HtmlNode.CreateNode(@"<img src=""123.jpg"" />", options => options.OptionWriteEmptyNodes = true);

Let me know if you successfully implemented the solution.

Best Regards,

Jon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants