Mark() публичный Метод

public Mark ( SourceInfo sourceInfo, IMarkdownContext context ) : StringBuffer
sourceInfo SourceInfo
context IMarkdownContext
Результат StringBuffer
Пример #1
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownTableBlockToken token, MarkdownBlockContext context)
        {
            StringBuffer result = "<table>\n<thead>\n";

            // header
            result += "<tr>\n";
            var cell = StringBuffer.Empty;
            var c    = engine.SwitchContext(context.InlineContext);

            for (int i = 0; i < token.Header.Length; i++)
            {
                if (i < token.Align.Length && token.Align[i] != Align.NotSpec)
                {
                    result += "<th style=\"text-align:";
                    result += token.Align[i].ToString().ToLower();
                    result += "\">";
                }
                else
                {
                    result += "<th>";
                }
                result += engine.Mark(token.Header[i]);
                result += "</th>\n";
            }
            result += "</tr>\n";
            result += "</thead>\n";
            result += "<tbody>\n";
            // body
            for (int i = 0; i < token.Cells.Length; i++)
            {
                var row = token.Cells[i];
                result += "<tr>\n";
                for (int j = 0; j < row.Length; j++)
                {
                    if (j < token.Align.Length && token.Align[j] != Align.NotSpec)
                    {
                        result += "<td style=\"text-align:";
                        result += token.Align[j].ToString().ToLower();
                        result += "\">";
                    }
                    else
                    {
                        result += "<td>";
                    }
                    result += engine.Mark(row[j]);
                    result += "</td>\n";
                }
                result += "</tr>\n";
            }
            engine.SwitchContext(c);
            return(result + "</tbody>\n" + "</table>\n");
        }
Пример #2
0
        public virtual StringBuffer Render(MarkdownEngine engine, GfmDelInlineToken token, MarkdownInlineContext context)
        {
            var result = (StringBuffer)"<del>";

            result += engine.Mark(token.Content);
            result += "</del>";
            return(result);
        }
Пример #3
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownParagraphBlockToken token, MarkdownBlockContext context)
        {
            StringBuffer result = "<p>";
            var          c      = engine.SwitchContext(context.InlineContext);

            result += engine.Mark(token.Content);
            engine.SwitchContext(c);
            result += "</p>\n";
            return(result);
        }
Пример #4
0
        protected virtual StringBuffer ApplyInline(MarkdownEngine engine, StringBuffer content, MarkdownBlockContext context)
        {
            if (content == StringBuffer.Empty)
            {
                return(StringBuffer.Empty);
            }
            var c      = engine.SwitchContext(context.InlineContext);
            var result = engine.Mark(content.ToString());

            engine.SwitchContext(c);
            return(result);
        }
Пример #5
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownHtmlBlockToken token, MarkdownBlockContext context)
 {
     if (!token.Pre && !engine.Options.Pedantic)
     {
         var c      = engine.SwitchContext(context.InlineContext);
         var result = engine.Mark(token.Content);
         engine.SwitchContext(c);
         return(result);
     }
     else
     {
         return(token.Content);
     }
 }
Пример #6
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownHeadingBlockToken token, MarkdownBlockContext context)
 {
     string level = token.Depth.ToString();
     var result = (StringBuffer)"<h"
         + level
         + " id=\""
         + engine.Options.HeaderPrefix
         + Regex.Replace(token.Content.ToLower(), @"[^\w]+", "-")
         + "\">";
     var c = engine.SwitchContext(context.InlineContext);
     result += engine.Mark(token.Content);
     engine.SwitchContext(c);
     result += "</h";
     result += level;
     result += ">\n";
     return result;
 }
Пример #7
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownHeadingBlockToken token, MarkdownBlockContext context)
        {
            string level  = token.Depth.ToString();
            var    result = (StringBuffer)"<h"
                            + level
                            + " id=\""
                            + engine.Options.HeaderPrefix
                            + Regex.Replace(token.Content.ToLower(), @"[^\w]+", "-")
                            + "\">";
            var c = engine.SwitchContext(context.InlineContext);

            result += engine.Mark(token.Content);
            engine.SwitchContext(c);
            result += "</h";
            result += level;
            result += ">\n";
            return(result);
        }
Пример #8
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownLinkInlineToken token, MarkdownInlineContext context)
        {
            if (engine.Options.Sanitize)
            {
                string prot = null;

                try
                {
                    prot = Regex.Replace(StringHelper.DecodeURIComponent(StringHelper.Unescape(token.Href)), @"[^\w:]", string.Empty).ToLower();
                }
                catch (Exception)
                {
                    return(string.Empty);
                }

                if (prot.IndexOf("javascript:") == 0 || prot.IndexOf("vbscript:") == 0)
                {
                    return(string.Empty);
                }
            }

            var result = (StringBuffer)"<a href=\"" + token.Href + "\"";

            if (!string.IsNullOrEmpty(token.Title))
            {
                result = result + " title=\"" + token.Title + "\"";
            }

            result += ">";
            if (token.ShouldApplyInlineRule)
            {
                engine.SwitchContext(MarkdownInlineContext.IsInLink, true);
                result += engine.Mark(token.Text);
                engine.SwitchContext(MarkdownInlineContext.IsInLink, false);
            }
            else
            {
                result += token.Text;
            }

            result += "</a>";
            return(result);
        }
Пример #9
0
 public virtual StringBuffer Render(MarkdownEngine engine, GfmDelInlineToken token, MarkdownInlineContext context)
 {
     var result = (StringBuffer)"<del>";
     result += engine.Mark(token.Content);
     result += "</del>";
     return result;
 }
Пример #10
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownLinkInlineToken token, MarkdownInlineContext context)
        {
            if (engine.Options.Sanitize)
            {
                string prot = null;

                try
                {
                    prot = Regex.Replace(StringHelper.DecodeURIComponent(StringHelper.Unescape(token.Href)), @"[^\w:]", string.Empty).ToLower();
                }
                catch (Exception)
                {
                    return string.Empty;
                }

                if (prot.IndexOf("javascript:") == 0 || prot.IndexOf("vbscript:") == 0)
                {
                    return string.Empty;
                }
            }

            var result = (StringBuffer)"<a href=\"" + token.Href + "\"";
            if (!string.IsNullOrEmpty(token.Title))
            {
                result = result + " title=\"" + token.Title + "\"";
            }

            result += ">";
            if (token.ShouldApplyInlineRule)
            {
                engine.SwitchContext(MarkdownInlineContext.IsInLink, true);
                result += engine.Mark(token.Text);
                engine.SwitchContext(MarkdownInlineContext.IsInLink, false);
            }
            else
            {
                result += token.Text;
            }

            result += "</a>";
            return result;
        }
Пример #11
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownTableBlockToken token, MarkdownBlockContext context)
 {
     StringBuffer result = "<table>\n<thead>\n";
     // header
     result += "<tr>\n";
     var cell = StringBuffer.Empty;
     var c = engine.SwitchContext(context.InlineContext);
     for (int i = 0; i < token.Header.Length; i++)
     {
         if (i < token.Align.Length && token.Align[i] != Align.NotSpec)
         {
             result += "<th style=\"text-align:";
             result += token.Align[i].ToString().ToLower();
             result += "\">";
         }
         else
         {
             result += "<th>";
         }
         result += engine.Mark(token.Header[i]);
         result += "</th>\n";
     }
     result += "</tr>\n";
     result += "</thead>\n";
     result += "<tbody>\n";
     // body
     for (int i = 0; i < token.Cells.Length; i++)
     {
         var row = token.Cells[i];
         result += "<tr>\n";
         for (int j = 0; j < row.Length; j++)
         {
             if (j < token.Align.Length && token.Align[j] != Align.NotSpec)
             {
                 result += "<td style=\"text-align:";
                 result += token.Align[j].ToString().ToLower();
                 result += "\">";
             }
             else
             {
                 result += "<td>";
             }
             result += engine.Mark(row[j]);
             result += "</td>\n";
         }
         result += "</tr>\n";
     }
     engine.SwitchContext(c);
     return result + "</tbody>\n" + "</table>\n";
 }
Пример #12
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownParagraphBlockToken token, MarkdownBlockContext context)
 {
     StringBuffer result = "<p>";
     var c = engine.SwitchContext(context.InlineContext);
     result += engine.Mark(token.Content);
     engine.SwitchContext(c);
     result += "</p>\n";
     return result;
 }
Пример #13
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownHtmlBlockToken token, MarkdownBlockContext context)
 {
     if (!token.Pre && !engine.Options.Pedantic)
     {
         var c = engine.SwitchContext(context.InlineContext);
         var result = engine.Mark(token.Content);
         engine.SwitchContext(c);
         return result;
     }
     else
     {
         return token.Content;
     }
 }
Пример #14
0
 protected virtual StringBuffer ApplyInline(MarkdownEngine engine, StringBuffer content, MarkdownBlockContext context)
 {
     if (content == StringBuffer.Empty)
     {
         return StringBuffer.Empty;
     }
     var c = engine.SwitchContext(context.InlineContext);
     var result = engine.Mark(content.ToString());
     engine.SwitchContext(c);
     return result;
 }