Example #1
0
        public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownTableBlockToken token, MarkdownBlockContext context)
        {
            StringBuffer result = "<table";

            result  = AppendSourceInfo(result, renderer, token);
            result += ">\n<thead>\n";
            // header
            result += "<tr>\n";
            var cell = StringBuffer.Empty;

            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>";
                }
                foreach (var item in token.Header[i].Content.Tokens)
                {
                    result += renderer.Render(item);
                }
                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>";
                    }
                    foreach (var item in row[j].Content.Tokens)
                    {
                        result += renderer.Render(item);
                    }
                    result += "</td>\n";
                }
                result += "</tr>\n";
            }
            return(result + "</tbody>\n" + "</table>\n");
        }
Example #2
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");
        }
Example #3
0
        public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownTableBlockToken token, MarkdownBlockContext context)
        {
            var content = StringBuffer.Empty;

            // Header
            var headerContent = StringBuffer.Empty;

            for (int i = 0; i < token.Header.Length; i++)
            {
                var childContent = StringBuffer.Empty;
                foreach (var item in token.Header[i].Content.Tokens)
                {
                    childContent += renderer.Render(item);
                }
                headerContent += Insert(token.Header[i], "headerItem", childContent);
            }
            content += Insert(token.SourceInfo.LineNumber, token.SourceInfo.LineNumber, "Header", headerContent);

            // Body
            var bodyContent = StringBuffer.Empty;

            for (int i = 0; i < token.Cells.Length; i++)
            {
                var rowContent = StringBuffer.Empty;
                var row        = token.Cells[i];
                for (int j = 0; j < row.Length; j++)
                {
                    var childContent = StringBuffer.Empty;
                    foreach (var item in row[j].Content.Tokens)
                    {
                        childContent += renderer.Render(item);
                    }
                    rowContent += Insert(row[j], "RowItem", childContent);
                }
                bodyContent += Insert(row[0], "Row", rowContent);
            }
            content += Insert(token.Cells[0][0].SourceInfo.LineNumber, token.Cells[token.Cells.Length - 1][0].SourceInfo.LineNumber, "Body", bodyContent);
            return(Insert(token, ExposeTokenName(token), content));
        }
        public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownTableBlockToken token, MarkdownBlockContext context)
        {
            var content = StringBuffer.Empty;

            // Header
            var headerContent = StringBuffer.Empty;

            for (int i = 0; i < token.Header.Length; i++)
            {
                var childContent = StringBuffer.Empty;
                foreach (var item in token.Header[i].Content.Tokens)
                {
                    childContent += renderer.Render(item);
                }
                headerContent += this.Insert("headerItem", childContent, Type.NonLeaf);
            }
            content += this.Insert("Header", headerContent, Type.NonLeaf);

            // Body
            var bodyContent = StringBuffer.Empty;

            for (int i = 0; i < token.Cells.Length; i++)
            {
                var rowContent = StringBuffer.Empty;
                var row        = token.Cells[i];
                for (int j = 0; j < row.Length; j++)
                {
                    var childContent = StringBuffer.Empty;
                    foreach (var item in row[j].Content.Tokens)
                    {
                        childContent += renderer.Render(item);
                    }
                    rowContent += this.Insert("RowItem", childContent, Type.NonLeaf);
                }
                bodyContent += this.Insert("Row", rowContent, Type.NonLeaf);
            }
            content += this.Insert("Body", bodyContent, Type.NonLeaf);
            return(this.Insert("Table", content, Type.NonLeaf));
        }
Example #5
0
        public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownTableBlockToken token, MarkdownBlockContext context)
        {
            var content = StringBuffer.Empty;

            // Generate header line
            content += "|";
            foreach (var header in token.Header)
            {
                content += " ";
                foreach (var t in header.Tokens)
                {
                    content += render.Render(t);
                }
                content += " |";
            }
            content += "\n";

            // Generate align line
            content += "|";
            foreach (var align in token.Align)
            {
                switch (align)
                {
                case Align.NotSpec:
                    content += " --- ";
                    break;

                case Align.Left:
                    content += ":--- ";
                    break;

                case Align.Right:
                    content += " ---:";
                    break;

                case Align.Center:
                    content += ":---:";
                    break;

                default:
                    throw new NotSupportedException($"align:{align} doesn't support in GFM table");
                }
                content += "|";
            }
            content += "\n";

            // Generate content lines
            foreach (var row in token.Cells)
            {
                content += "| ";
                foreach (var column in row)
                {
                    foreach (var t in column.Tokens)
                    {
                        content += render.Render(t);
                    }
                    content += " |";
                }
                content += "\n";
            }

            return(content += "\n");
        }
Example #6
0
 public virtual StringBuffer Render(IMarkdownRenderer engine, MarkdownTableBlockToken token, MarkdownBlockContext context)
 {
     StringBuffer result = "<table>\n<thead>\n";
     // header
     result += "<tr>\n";
     var cell = StringBuffer.Empty;
     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>";
         }
         foreach (var item in token.Header[i].Tokens)
         {
             result += engine.Render(item);
         }
         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>";
             }
             foreach (var item in row[j].Tokens)
             {
                 result += engine.Render(item);
             }
             result += "</td>\n";
         }
         result += "</tr>\n";
     }
     return result + "</tbody>\n" + "</table>\n";
 }
Example #7
0
        public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownTableBlockToken token, MarkdownBlockContext context)
        {
            var content = StringBuffer.Empty;

            // Generate header line
            content += "|";
            foreach (var header in token.Header)
            {
                content += " ";
                foreach (var t in header.Content.Tokens)
                {
                    content += render.Render(t);
                }
                content += " |";
            }
            content += "\n";

            // Generate align line
            content += "|";
            foreach (var align in token.Align)
            {
                switch (align)
                {
                    case Align.NotSpec:
                        content += " --- ";
                        break;
                    case Align.Left:
                        content += ":--- ";
                        break;
                    case Align.Right:
                        content += " ---:";
                        break;
                    case Align.Center:
                        content += ":---:";
                        break;
                    default:
                        throw new NotSupportedException($"align:{align} doesn't support in GFM table");
                }
                content += "|";
            }
            content += "\n";

            // Generate content lines
            foreach (var row in token.Cells)
            {
                content += "| ";
                foreach (var column in row)
                {
                    foreach (var t in column.Content.Tokens)
                    {
                        content += render.Render(t);
                    }
                    content += " |";
                }
                content += "\n";
            }

            return content += "\n";
        }