Exemplo n.º 1
0
        internal void RenderLink(Markdown m, StringBuilder b, string link_text)
        {
            if (url.StartsWith("mailto:"))
            {
                b.Append("<a href=\"");
                Utils.HtmlRandomize(b, url);
                b.Append('\"');
                if (!String.IsNullOrEmpty(title))
                {
                    b.Append(" title=\"");
                    Utils.SmartHtmlEncodeAmpsAndAngles(b, title);
                    b.Append('\"');
                }
                b.Append('>');
                Utils.HtmlRandomize(b, link_text);
                b.Append("</a>");
            }
            else
            {
                HtmlTag tag = new HtmlTag("a");

                // encode url
                StringBuilder sb = m.GetStringBuilder();
                Utils.SmartHtmlEncodeAmpsAndAngles(sb, url);
                tag.attributes["href"] = sb.ToString();

                // encode title
                if (!String.IsNullOrEmpty(title))
                {
                    sb.Length = 0;
                    Utils.SmartHtmlEncodeAmpsAndAngles(sb, title);
                    tag.attributes["title"] = sb.ToString();
                }

                // Do user processing
                m.OnPrepareLink(tag);
                var href = tag.attributes["href"];
                if (href == "")
                {
                    tag = new HtmlTag("span");
                    tag.attributes["class"] = "brokenlink";
                }
                else if (href.StartsWith("http://") || href.StartsWith("https://"))
                {
                    tag.attributes["class"] = "foreignlink";
                }

                // Render the opening tag
                tag.RenderOpening(b);

                b.Append(link_text);                      // Link text already escaped by SpanFormatter
                b.AppendFormat("</{0}>", tag.name);
                if (href == "")
                {
                    m.AfterBrokenLink(b, sb.ToString(), link_text);
                }
            }
        }