Replies: 1 comment 1 reply
-
@Joevdwalt Welcome! Not breaking any rules. 😄 The current markdown renderer for tables is just changing how borders appear and wouldn't be very suitable to generate HTML. You would want to write something that converts a table to HTML. Here is a basic extension method you can use to convert a public static string ToHtml(this Table table)
{
var builder = new StringBuilder();
var ctx = new RenderContext(AnsiConsole.Profile.Capabilities);
builder.Append("<table style=\"border: 1px solid black;\">");
{
builder.Append("<tr>");
foreach (var column in table.Columns)
{
builder.Append("<th style=\"border: 1px solid black;\">");
AppendRenderable(builder, ctx, column.Header);
builder.Append("</th>");
}
builder.Append("</tr>");
}
foreach(var row in table.Rows)
{
builder.Append("<tr>");
foreach(var item in row)
{
builder.Append("<td style=\"border: 1px solid black;\">");
AppendRenderable(builder, ctx, item);
builder.Append("</td>");
}
builder.Append("</tr>");
}
builder.Append("</table>");
return builder.ToString();
}
private static void AppendRenderable(StringBuilder builder, RenderContext ctx, IRenderable renderable)
{
if (renderable is Table columnTable)
{
builder.Append(ToHtml(columnTable));
}
else
{
builder.Append("<pre>");
foreach (var foo in renderable.Render(ctx, 120))
{
if (foo.IsLineBreak)
{
builder.Append("<br />");
}
else
{
builder.Append(foo.Text);
}
}
builder.Append("</pre>");
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all,
First time posting here, so apologies if I am breaking rules. Really enjoying what you guys have built here already.
One of the things that I use a cli tool for the most is formatting data into some kind of report. I see the table already supports markdown, but was wondering if it would be feasible to do one for html?
I try to do a pull request for this? Not sure if this has been requested before or if someone is already working on something like this?
Beta Was this translation helpful? Give feedback.
All reactions