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); } } }
internal void RenderLink(Markdown m, StringBuilder b, string link_text, List <string> specialAttributes) { if (this.Url.StartsWith("mailto:")) { b.Append("<a href=\""); Utils.HtmlRandomize(b, this.Url); b.Append('\"'); if (!String.IsNullOrEmpty(this.Title)) { b.Append(" title=\""); Utils.SmartHtmlEncodeAmpsAndAngles(b, this.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, this.Url); tag.attributes["href"] = sb.ToString(); // encode title if (!String.IsNullOrEmpty(this.Title)) { sb.Length = 0; Utils.SmartHtmlEncodeAmpsAndAngles(sb, this.Title); tag.attributes["title"] = sb.ToString(); } if (specialAttributes.Any()) { LinkDefinition.HandleSpecialAttributes(specialAttributes, sb, tag); } // Do user processing m.OnPrepareLink(tag); // Render the opening tag tag.RenderOpening(b); b.Append(link_text); // Link text already escaped by SpanFormatter b.Append("</a>"); } }
internal void RenderLink(Markdown m, StringBuilder b, string linkText) { 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, linkText); b.Append("</a>"); } else { var tag = new HtmlTag("a"); // encode url var 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); // Render the opening tag tag.RenderOpening(b); b.Append(linkText); // Link text already escaped by SpanFormatter b.Append("</a>"); } }
internal void RenderLink(Markdown m, StringBuilder b, string link_text, List <string> specialAttributes) { if (this.Url.StartsWith("mailto:")) { b.Append("<a href=\""); Utils.HtmlRandomize(b, this.Url); b.Append('\"'); if (!String.IsNullOrEmpty(this.Title)) { b.Append(" title=\""); Utils.SmartHtmlEncodeAmpsAndAngles(b, this.Title); b.Append('\"'); } b.Append('>'); Utils.HtmlRandomize(b, link_text); b.Append("</a>"); } else { HtmlTag tag = new HtmlTag("a"); var url = this.Url; if (m.DocNetMode && m.ConvertLocalLinks) { // A few requirements before we can convert local links: // 1. Link contains .md // 2. Link is relative // 3. Link is included in the index var index = url.LastIndexOf(".md", StringComparison.OrdinalIgnoreCase); if (index >= 0) { var linkProcessor = m.LocalLinkProcessor; if (linkProcessor != null) { url = linkProcessor(url); } else { Uri uri; if (Uri.TryCreate(url, UriKind.Relative, out uri)) { url = String.Concat(url.Substring(0, index), ".htm", url.Substring(index + ".md".Length)); } } } } // encode url StringBuilder sb = m.GetStringBuilder(); Utils.SmartHtmlEncodeAmpsAndAngles(sb, url); tag.attributes["href"] = sb.ToString(); // encode title if (!String.IsNullOrEmpty(this.Title)) { sb.Length = 0; Utils.SmartHtmlEncodeAmpsAndAngles(sb, this.Title); tag.attributes["title"] = sb.ToString(); } if (specialAttributes.Any()) { LinkDefinition.HandleSpecialAttributes(specialAttributes, sb, tag); } // Do user processing m.OnPrepareLink(tag); // Render the opening tag tag.RenderOpening(b); b.Append(link_text); // Link text already escaped by SpanFormatter b.Append("</a>"); } }