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.
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.
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.
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
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:
One not is that after the local links had been parsed i had to remove the first /home.
Hope this helps someone else.
Cheers!
Helped me out with the links in an RSS Feed. :)
Just one thing - you have an invalid line of code in the snippet:
Thanks Damian,
Glad it helped.
L
is working on a reply...