-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
Problems formatting HTML #147
Comments
Parsing HTML works fine, except - like in your case - when it includes CSS styles and JavaScript. Both have curly braces in their syntax, which Smart.Format interprets as
|
The HTML is user input, including the variables to replace. It makes it hard to implement your suggestions. :) Did you see the difference between version 2.5.2 and 2.6.2? |
If it is all user input, it takes only few lines of code to solve with AngleSharp: using AngleSharp;
using AngleSharp.Html.Dom;
using AngleSharp.Html.Parser;
// Create a new parser front-end (can be re-used)
var parser = new HtmlParser();
// Get the DOM representation
IHtmlDocument htmlDocument = parser.ParseDocument(yourUserHtmlInput);
htmlDocument.Body.InnerHtml = Smart.Format(htmlDocument.Body.InnerHtml, yourDataItems);
// This gets the complete HTML as a string
var result = htmlDocument.ToHtml(); Hope this helps. I did not analyze the differences between versions, because HTML containing CSS styles and/or JavaScript cannot be processed reliably with |
Thank you @axunonb |
Welcome |
* Reference to issues #148, #147, #143 * Updated README.md * Fix for #149 (comment) * Update CHANGES.md
Hi.
I have the following code to format a string containing HTML:
If I run this with version 2.6.2 the formatter does nothing (no replacements).
If I run this with version 2.5.2 the formatter works more or less correctly (does the replacements but it introduces some errors in the HTML).
This is visible with the following files:
InputHtml.txt - the input HTML
OutputHtml262.txt - the output produced with 2.6.2
OutputHtml252.txt - the output produced with 2.5.2
OutputHtml.txt - the expected output
Comparing 2.6.2 with the expected output... no replacements at all.
Comparing 2.5.2 with the expected output... replacements OK but errors in HTML (e.g. line 68, col 9).
Is this a bug? Something that I need to change in the upgrade from 2.5.2 to 2.6.2?
The text was updated successfully, but these errors were encountered: