HandleSpecialAttributes() private static method

private static HandleSpecialAttributes ( List specialAttributes, StringBuilder sb, HtmlTag tag ) : void
specialAttributes List
sb StringBuilder
tag HtmlTag
return void
コード例 #1
0
        internal void RenderImg(Markdown m, StringBuilder b, string alt_text, List <string> specialAttributes)
        {
            HtmlTag tag = new HtmlTag("img");

            // encode url
            StringBuilder sb = m.GetStringBuilder();

            Utils.SmartHtmlEncodeAmpsAndAngles(sb, Url);
            tag.attributes["src"] = sb.ToString();

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

            // encode title
            if (!String.IsNullOrEmpty(Title))
            {
                sb.Length = 0;
                Utils.SmartHtmlEncodeAmpsAndAngles(sb, Title);
                tag.attributes["title"] = sb.ToString();
            }
            if (specialAttributes.Any())
            {
                LinkDefinition.HandleSpecialAttributes(specialAttributes, sb, tag);
            }
            tag.closed = true;

            m.OnPrepareImage(tag, m.RenderingTitledImage);

            tag.RenderOpening(b);
        }
コード例 #2
0
        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>");
            }
        }
コード例 #3
0
        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>");
            }
        }