public XDoc External( [DekiExtParam("link")] string link ) { // store the original link value string originalLink = link; // remove spaces from the link link = link.Trim(); // extract the title if there is one (indicated by the first space) string title = String.Empty; int titleIndex = link.IndexOf(' '); if (0 < titleIndex) { title = link.Substring(titleIndex + 1, link.Length - titleIndex - 1); link = link.Substring(0, titleIndex); } // if the url is valid return it as a link - otherwise return the original text XDoc result = new XDoc("html").Start("body"); XUri uri = null; if (XUri.TryParse(link, out uri)) { result.Start("a").Attr("href", link).AddNodes(DekiScriptLibrary.WebHtml(title, null, null, null)["body"]).End(); } else { result.AddNodes(DekiScriptLibrary.WebHtml("[" + originalLink + "]", null, null, null)["body"]); } result.End(); return(result); }
public XDoc Internal( [DekiExtParam("link")] string link, [DekiExtParam("language", true)] string language ) { // extract the link title string displayName = null; int displayNameIndex = link.IndexOf('|'); if (0 < displayNameIndex) { displayName = link.Substring(displayNameIndex + 1, link.Length - displayNameIndex - 1); link = link.Substring(0, displayNameIndex); } Title title = Title.FromUIUri(null, link, true); if (("." == title.Path) && (title.HasAnchor)) { link = "#" + AnchorEncode(title.Anchor); } else { link = LocalUrl(language, title.AsPrefixedDbPath(), title.Query); if (title.HasAnchor) { link += "#" + AnchorEncode(title.Anchor); } } // return the internal link XDoc result = new XDoc("html").Start("body").Start("a").Attr("href", link).AddNodes(DekiScriptLibrary.WebHtml(displayName ?? String.Empty, null, null, null)["body"]).End().End(); return(result); }