Below is the text from the database and what is retruned.
<p>Lorem ipsum dolor <strong>sit amet,</strong> consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
"Lorem ipsum dolor sit amet,"
As you can see it seems to be breaking after the strong tag closes. Has anyone else had this problem, or am I just doing something wrong?
So looks like your strip html is working but I would expect it also to be able to handle strings without html elements. Error messgae is below I hope this helps with your testing. John
Error Loading Razor Script (file: Calendar List) Object reference not set to an instance of an object. at umbraco.MacroEngines.Library.RazorLibraryCore.StripHtmlTags(String html, List`1 tags) in C:\Work Files\udev\umbraco.MacroEngines.Juno\RazorDynamicNode\RazorLibraryCore.cs:line 511 at umbraco.MacroEngines.Library.RazorLibraryCore.StripHtml(String html) in C:\Work Files\udev\umbraco.MacroEngines.Juno\RazorDynamicNode\RazorLibraryCore.cs:line 474 at ASP._Page_macroScripts_CalendarList_cshtml.Execute() in c:\git\s4l\Site\macroScripts\CalendarList.cshtml:line 66 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) at System.Web.WebPages.WebPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer) at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage) in C:\Work Files\udev\umbraco.MacroEngines.Juno\RazorCore\RazorMacroEngine.cs:line 113 at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage) in C:\Work Files\udev\.MacroEngines.Juno\RazorCore\RazorMacroEngine.cs:line 160
That should work, but the Library.StripHtml method is based on HtmlAgilityPack - so if it's not being stripped that would suggest the fault lies there. Could you try without specifying the tags list to strip out?
I should have responded back to my own post. For some reason, and we have had this issue before, is that some nodes suddenly became unpublished. I did a batch publish of the file, but it did not actually publish each node. Meaning my 'bodyText' property was not rendering. I think it had to rebuild the XML. Our site is over 2000 pages. Not sure if this is an issue with Umbraco or anything else. But by republishing the nodes individually I was able to get the content to render, without the tags specified. It all worked out in the end.
Library.StripHtml v 4.7.1
Hi,
I've just attempted to use the code
Below is the text from the database and what is retruned.
As you can see it seems to be breaking after the strong tag closes. Has anyone else had this problem, or am I just doing something wrong?
John
Confirmed, this doesn't work for me either.
Alternatively, you can use this @function:
Thanks Sebastiaan,
In the end I created a extension to the library using a regex to do this.
I want to add the code snippet but the style is not avaiable in my comment window!?
I would never ever recommend you do HTML sanitizing with regex, so many pitfalls there. http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags
Just paste the code snippet, and format it with "Preformatted"!
I agree with Seb - regex are dangerous for anything but the most simple examples. Use the HtmlAgility pack - it's much more robust.
Could you please paste your original HTML including any open/closing tags?
The StripHTML function should work for this (and it doesn't use regex)
@Gareth I took that same HTML from the opening post with the <strong> mixed in and found the same problem.
So like this: "Lorem ipsum dolor sit amet,<strong>I am bold</strong> Lorem ipsum dolor sit amet"
Yup, that should do the trick!
Please test this build http://dl.dropbox.com/u/2923715/LatestRazorMacroEngine-Only.zip
I have rewritten @Library.StripHtml to use HtmlAgilityPack
Hi Gareth,
Just tested the updated dll my results are below;
Works fine:
Errors:
So looks like your strip html is working but I would expect it also to be able to handle strings without html elements. Error messgae is below I hope this helps with your testing. John
Can stripHTML strip out object tags?
This is my current version. But it seems like it is stripping everything else out but the object tag, Making my Macro not render.
@Library.Truncate(Library.StripHtml(@nodeItem.GetProperty("bodyText").Value, "img", "a", "object", "param", "table", "embed", "iframe", "strong", "b", "p"),300)
Hi Carlos
That should work, but the Library.StripHtml method is based on HtmlAgilityPack - so if it's not being stripped that would suggest the fault lies there.
Could you try without specifying the tags list to strip out?
Gareth
Gareth
I should have responded back to my own post. For some reason, and we have had this issue before, is that some nodes suddenly became unpublished. I did a batch publish of the file, but it did not actually publish each node. Meaning my 'bodyText' property was not rendering. I think it had to rebuild the XML. Our site is over 2000 pages. Not sure if this is an issue with Umbraco or anything else. But by republishing the nodes individually I was able to get the content to render, without the tags specified. It all worked out in the end.
Thanks.
Carlos
This comment has been edited and moved to a more appropriate topic.
is working on a reply...