Created
November 12, 2012 14:26
-
-
Save kevinblake/4059711 to your computer and use it in GitHub Desktop.
Umbraco - render local links from string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LinkRenderer | |
{ | |
public static string Transform(string richText) | |
{ | |
// take a rich text string, parse the local links | |
Regex ll = new Regex("(/{localLink:)(.*?)}"); | |
var linkRenderer = new LinkRenderer(); | |
MatchEvaluator myEvaluator = new MatchEvaluator(MatchLocalLinks); | |
var LocalLinksParsed = ll.Replace(richText, myEvaluator); | |
return HttpUtility.HtmlDecode(LocalLinksParsed); | |
} | |
private static string MatchLocalLinks(Match m) | |
{ | |
var noHome = Regex.Replace(umbraco.library.NiceUrl(int.Parse(m.Result("$2"))), ".*/home(.*)", "$2"); | |
return noHome; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, this helped me get around an umbraco bug! The only feedback I would give is that you don't need the line "var linkRenderer = new LinkRenderer();" because it's never used.