Exemple #1
0
        /// <summary>
        /// Renders the img.
        /// </summary>
        /// <param name="m">The m.</param>
        /// <param name="b">The b.</param>
        /// <param name="alt_text">The alt text.</param>
        internal void RenderImg(Markdown m, StringBuilder b, string alt_text)
        {
            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();
            }

            tag.closed = true;

            m.OnPrepareImage(tag, m.RenderingTitledImage);

            tag.RenderOpening(b);
        }
Exemple #2
0
        /// <summary>
        /// Renders the link.
        /// </summary>
        /// <param name="m">The m.</param>
        /// <param name="b">The b.</param>
        /// <param name="link_text">The link text.</param>
        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);

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

                b.Append(link_text);                      // Link text already escaped by SpanFormatter
                b.Append("</a>");
            }
        }