// Constructor
 public Markdown()
 {
     HtmlClassFootnotes   = "footnotes";
     m_StringBuilder      = new StringBuilder();
     m_StringBuilderFinal = new StringBuilder();
     m_StringScanner      = new StringScanner();
     m_SpanFormatter      = new SpanFormatter(this);
     m_LinkDefinitions    = new Dictionary <string, LinkDefinition>(StringComparer.CurrentCultureIgnoreCase);
     m_Footnotes          = new Dictionary <string, Block>();
     m_UsedFootnotes      = new List <Block>();
     m_UsedHeaderIDs      = new Dictionary <string, bool>();
 }
        // Render a list of tokens to a destinatino string builder.
        private void Render(StringBuilder sb, string str)
        {
            foreach (Token t in m_Tokens)
            {
                switch (t.type)
                {
                case TokenType.Text:
                    // Append encoded text
                    m_Markdown.HtmlEncode(sb, str, t.startOffset, t.length);
                    break;

                case TokenType.HtmlTag:
                    // Append html as is
                    Utils.SmartHtmlEncodeAmps(sb, str, t.startOffset, t.length);
                    break;

                case TokenType.Html:
                case TokenType.opening_mark:
                case TokenType.closing_mark:
                case TokenType.internal_mark:
                    // Append html as is
                    sb.Append(str, t.startOffset, t.length);
                    break;

                case TokenType.br:
                    sb.Append("<br />\n");
                    break;

                case TokenType.open_em:
                    sb.Append("<em>");
                    break;

                case TokenType.close_em:
                    sb.Append("</em>");
                    break;

                case TokenType.open_strong:
                    sb.Append("<strong>");
                    break;

                case TokenType.close_strong:
                    sb.Append("</strong>");
                    break;

                case TokenType.code_span:
                    sb.Append("<code>");
                    m_Markdown.HtmlEncode(sb, str, t.startOffset, t.length);
                    sb.Append("</code>");
                    break;

                case TokenType.link:
                {
                    LinkInfo li = (LinkInfo)t.data;
                    var      sf = new SpanFormatter(m_Markdown);
                    sf.DisableLinks = true;

                    li.def.RenderLink(m_Markdown, sb, sf.Format(li.link_text));
                    break;
                }

                case TokenType.img:
                {
                    LinkInfo li = (LinkInfo)t.data;
                    li.def.RenderImg(m_Markdown, sb, li.link_text);
                    break;
                }

                case TokenType.footnote:
                {
                    FootnoteReference r = (FootnoteReference)t.data;
                    sb.Append("<sup id=\"fnref:");
                    sb.Append(r.id);
                    sb.Append("\"><a href=\"#fn:");
                    sb.Append(r.id);
                    sb.Append("\" rel=\"footnote\">");
                    sb.Append(r.index + 1);
                    sb.Append("</a></sup>");
                    break;
                }

                case TokenType.abbreviation:
                {
                    Abbreviation a = (Abbreviation)t.data;
                    sb.Append("<abbr");
                    if (!String.IsNullOrEmpty(a.Title))
                    {
                        sb.Append(" title=\"");
                        m_Markdown.HtmlEncode(sb, a.Title, 0, a.Title.Length);
                        sb.Append("\"");
                    }
                    sb.Append(">");
                    m_Markdown.HtmlEncode(sb, a.Abbr, 0, a.Abbr.Length);
                    sb.Append("</abbr>");
                    break;
                }
                }

                FreeToken(t);
            }
        }