Copied to clipboard

Flag this post as spam?

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


  • Bob Banks 16 posts 36 karma points
    Apr 11, 2014 @ 23:55
    Bob Banks
    0

    Bad HTML generated by Umbraco.Truncate()?

    @Umbraco.Truncate("<p><strong> this is my really really really really really really short blog post</strong></p>",10,false)

    results in

    <p><strong this is</strong></p></div>

    Notice the open strong tag is broken.  Has anyone else noticed this? About to just roll my own.

     


  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Apr 12, 2014 @ 00:04
    Jeavon Leopold
    0

    Hi Bob,

    I'm pretty sure there is method in here that would do the job properly.

    Jeavon

  • Mike Chambers 636 posts 1253 karma points c-trib
    May 02, 2014 @ 23:05
    Mike Chambers
    0

    Another approach is to leverage Tidy... I found you have to help a little for when the trunacte causes a break in a tag, but quite straight forward..

    Sorry could only find xslt example.. but should apply in razor or usercontrol too..

    <!-- we may be splitting mid tag!! -->
                                  <xsl:variable name="xmlFragment">
                                    <xsl:value-of select="substring(umbraco.library:GetXmlNodeById($nodeId)/abstract, 1, $abstractLength)" disable-output-escaping="yes"/>
                                  </xsl:variable>
                                  <!-- help tidy out by removing any unclosed tag at the end of the string not so hot at this itself -->
                                  <xsl:variable name="regExp"><xsl:text disable-output-escaping="yes">[\s\S]*&gt;[^&lt;]*</xsl:text></xsl:variable>
                                  <xsl:value-of disable-output-escaping="yes" select="umbraco.library:Tidy(Exslt.ExsltRegularExpressions:match($xmlFragment, $regExp), false)" />

     

     

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies