Copied to clipboard

Flag this post as spam?

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


  • Lachlann 344 posts 626 karma points
    Jun 23, 2011 @ 10:56
    Lachlann
    0

    RUnning RegEx on richtext AFTER localLink parser

    Hello all,

     

    I am trying to run a regular expression on some rich text but the regex is designed to affect the internal URLs inserted in the rich text by the user. However I think that at the time that I am trying to run my regex the LocalLink parser has not run.

    Here is my regex:

    <xsl:value-of select="Exslt.ExsltRegularExpressions:replace($richText, '(.*/glossary)/(.*)', 'mUs', '$1.aspx#$2' )" disable-output-escaping="no" />

    When my richtext has an internal link insterted that once parsed will match the expression it doesnt get matched, But when i just type in the link as rich text it gets parsed. This makes me think that at the time of parsing the text the Local Links havnt yet been converted to URLs.

    Does anyone have any ideas.

    L

  • Lachlann 344 posts 626 karma points
    Jun 23, 2011 @ 12:32
    Lachlann
    1

    Okay did a bit more searching and couldnt find anything about the local links and when they are parsed. But I did realise that parsing them myself wouldn't be too difficult.

    So before I did the regex i needed to on the rich text i parsed the local links as follows:

     

        public class MyClass
        {
            public static string MakeGlossaryLink(string richText)
            {
                // take a rich text string, parse the local links then look for glossary links and replace them with anchors

                Regex ll = new Regex("(/{localLink:)(.*)}");
                MyClass = new MyClass();

                MatchEvaluator myEvaluator = new MatchEvaluator(MatchLocalLinks);

                var LocalLinksParsed = ll.Replace(richText, myEvaluator);
                return  HttpUtility.HtmlDecode(Regex.Replace(LocalLinksParsed, "(.*/glossary)/(.*)", "$1.aspx#$2"));
            }

            private static string MatchLocalLinks(Match m)
            {
                var noHome = Regex.Replace(umbraco.library.NiceUrl(int.Parse(m.Result("$2"))), ".*/home(.*)", "$2");
                return noHome;
            }

        }

     

    One not is that after the local links had been parsed i had to remove the first /home.

     

    Hope this helps someone else.

     

  • Damian Green 452 posts 1433 karma points
    Jun 27, 2012 @ 14:21
    Damian Green
    1

    Cheers!

    Helped me out with the links in an RSS Feed. :)

    Just one thing - you have an invalid line of code in the snippet:

    MyClassc=newMyClass();

     

  • Lachlann 344 posts 626 karma points
    Jun 27, 2012 @ 14:41
    Lachlann
    0

    Thanks Damian,

     

    Glad it helped.

     

    L

Please Sign in or register to post replies

Write your reply to:

Draft