Exemple #1
0
        public override string Format(IPostParsingContext context, ITextFormatter <IPostParsingContext> formatter)
        {
            string rawUrl = this.DefaultOrValue;
            string title  = null;

            if (rawUrl.ToLower() != this.InnerText.ToLower())
            {
                title = this.GetInnerHTML(context, formatter);
            }
            return(UrlProcessor.ProcessLink(rawUrl, title, false));
        }
Exemple #2
0
        public override string Format(IPostParsingContext context, ITextFormatter <IPostParsingContext> formatter)
        {
            var urlInfo = UrlProcessor.Process(this.InnerText);

            if (urlInfo.isLocal && urlInfo.relativeUrl.StartsWith("/user/upload/"))
            {
                return("<f:img><f:src>" + urlInfo.relativeUrl + "</f:src><f:alt>" + urlInfo.relativeUrl + "</f:alt></f:img>");
            }
            else
            {
                return("<a href=\"" + urlInfo.relativeUrl + "\">" + urlInfo.relativeUrl + "</a>");
            }
        }
Exemple #3
0
        public static string ProcessLink(string link, string title, bool shortenRelative)
        {
            bool   isExternal = true;
            string url;

            if (shortenRelative)
            {
                var urlInfo = UrlProcessor.Process(link);
                url        = urlInfo.relativeUrl;
                isExternal = !urlInfo.isLocal;
            }
            else
            {
                var urlInfo = new Uri(link);
                url = urlInfo.ToString();
            }
            if (isExternal)
            {
                if (title == null)
                {
                    title = Safe(url);
                }
            }
            else
            {
                var linkInfo = URL.UrlManager.Parse(url, new System.Collections.Specialized.NameValueCollection(), true);
                if (linkInfo == null)
                {
                    throw new FLocalException("Unable to parse link: " + url);
                }
                url = linkInfo.canonicalFull;
                if (title == null)
                {
                    title = Safe(linkInfo.title);
                }
            }
            string result = String.Format("<a href=\"{0}\"{1}>{2}</a>", url, (isExternal ? " class=\"external\"" : ""), title);

            return(result);
        }