mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-05 00:56:39 +00:00
LibMarkdown: Output alignment when rendering HTML tables
Previously, only terminal output aligned table column contents correctly. Now, we apply a `text-align` to each cell. This does not actually *work* however, since LibWeb's table layout code is not yet fully functional.
This commit is contained in:
parent
fee43e3544
commit
93ef8c8080
Notes:
sideshowbarker
2024-07-17 21:34:21 +09:00
Author: https://github.com/AtkinsSJ
Commit: 93ef8c8080
Pull-request: https://github.com/SerenityOS/serenity/pull/11650
Reviewed-by: https://github.com/petelliott ✅
1 changed files with 14 additions and 2 deletions
|
@ -68,13 +68,25 @@ String Table::render_for_terminal(size_t view_width) const
|
|||
|
||||
String Table::render_to_html(bool) const
|
||||
{
|
||||
auto alignment_string = [](Alignment alignment) {
|
||||
switch (alignment) {
|
||||
case Alignment::Center:
|
||||
return "center"sv;
|
||||
case Alignment::Left:
|
||||
return "left"sv;
|
||||
case Alignment::Right:
|
||||
return "right"sv;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
};
|
||||
|
||||
StringBuilder builder;
|
||||
|
||||
builder.append("<table>");
|
||||
builder.append("<thead>");
|
||||
builder.append("<tr>");
|
||||
for (auto& column : m_columns) {
|
||||
builder.append("<th>");
|
||||
builder.appendff("<th style='text-align: {}'>", alignment_string(column.alignment));
|
||||
builder.append(column.header.render_to_html());
|
||||
builder.append("</th>");
|
||||
}
|
||||
|
@ -85,7 +97,7 @@ String Table::render_to_html(bool) const
|
|||
builder.append("<tr>");
|
||||
for (auto& column : m_columns) {
|
||||
VERIFY(i < column.rows.size());
|
||||
builder.append("<td>");
|
||||
builder.appendff("<td style='text-align: {}'>", alignment_string(column.alignment));
|
||||
builder.append(column.rows[i].render_to_html());
|
||||
builder.append("</td>");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue