Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Antony Briggs 78 posts 103 karma points
    Jan 13, 2010 @ 10:11
    Antony Briggs
    5

    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):

    <xsl:stylesheet 
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
        xmlns:pageScript="urn:pageScript"
        exclude-result-prefixes="pageScript msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets">

    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.

  • Chris Houston 535 posts 980 karma points MVP admin c-trib
    May 15, 2010 @ 21:14
    Chris Houston
    0

    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

  • Thomas Kahn 602 posts 506 karma points
    Nov 16, 2011 @ 08:51
    Thomas Kahn
    0

    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

  • Simon steed 374 posts 686 karma points
    Nov 24, 2011 @ 13:01
    Simon steed
    0

    Thanks Anthony - just worked for me on a 4.7.1 upgrade, obviously a bug with the core but your solution works fine.

Please Sign in or register to post replies

Write your reply to:

Draft