Temporary workaround for RemoveFirstParagraphTag bug
Hey, I've been using Umbraco for a while now and feel like I never give anything back, so heres a quick post on a workaround for a little bug I found in the xslt library. (The bug has been reported by someone else in codeplex, if this affects you please go vote for it.)
library.RemoveFirstParagraphTag has the following line:
text = text.Trim().Replace("\n", string.Empty).Replace("\r", string.Empty);
Which which combined with the Richtext editor inserting \r\n chars in the html source of long paragraphs results in some of the white space between words disappearing alltogether.
Personally I don't see the need for this replacement at all as html will treat both \r and \n as whitespace and I can't see that TinyMCE will insert newlines in the middle of tags. If I'm proven wrong about that then the replace needs to be upgraded to a regex replace that only removes \r and \n's from within tags.
Anyway to the wrokaround: xslt allows inline code in many languages but here I use c# so I could simply copy the routine from the ubraco.library and remove the offending line.
<msxml:script language="C#" implements-prefix="pageScript"> <msxml:assembly name="System.Web" /> <msxml:using namespace="System.Web" /> <![CDATA[ public String RemoveFirstParagraphTag(string text) { text = text.Trim(); if (text.Length > 5) { if (text.ToUpper().Substring(0, 3) == "<P>") text = text.Substring(3, text.Length - 3); if (text.ToUpper().Substring(text.Length - 4, 4) == "</P>") text = text.Substring(0, text.Length - 4); } return text; } ]]> </msxml:script>
bung this in your xslt (i stick it after the currentPage parameter) then change your stylesheet statement to (changes in bold and italic):
I'm using Umbraco 4.7.1 (Assembly version: 1.0.4281.20201) and when I use umbraco.library:RemoveFirstParagraphTag it still doesn't work. I have tried searching Codeplex for an issue to vote for, but I can't find any.
Has this problem been fixed in one version and then surfaced again in a later one?
Temporary workaround for RemoveFirstParagraphTag bug
Hey, I've been using Umbraco for a while now and feel like I never give anything back, so heres a quick post on a workaround for a little bug I found in the xslt library. (The bug has been reported by someone else in codeplex, if this affects you please go vote for it.)
library.RemoveFirstParagraphTag has the following line:
Which which combined with the Richtext editor inserting \r\n chars in the html source of long paragraphs results in some of the white space between words disappearing alltogether.
Personally I don't see the need for this replacement at all as html will treat both \r and \n as whitespace and I can't see that TinyMCE will insert newlines in the middle of tags. If I'm proven wrong about that then the replace needs to be upgraded to a regex replace that only removes \r and \n's from within tags.
Anyway to the wrokaround: xslt allows inline code in many languages but here I use c# so I could simply copy the routine from the ubraco.library and remove the offending line.
bung this in your xslt (i stick it after the currentPage parameter) then change your stylesheet statement to (changes in bold and italic):
and you can then replace your calls to umbraco.library:RemoveFirstParagraphTag with pageScript:RemoveFirstParagraphTag
Obviously, when Umbraco is fixed, you can undo all the above to get rid of the .net compiler from the equation.
Hi Anthony,
Just what I was looking for, we just can across this bug.
Just a quick note the other option is to put this function into an XSLT extension file of your own which then means the C# is pre-complied.
Cheers,
Chris
I'm using Umbraco 4.7.1 (Assembly version: 1.0.4281.20201) and when I use umbraco.library:RemoveFirstParagraphTag it still doesn't work. I have tried searching Codeplex for an issue to vote for, but I can't find any.
Has this problem been fixed in one version and then surfaced again in a later one?
Regards,
Thomas
Thanks Anthony - just worked for me on a 4.7.1 upgrade, obviously a bug with the core but your solution works fine.
is working on a reply...