summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibMarkdown
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-01-05 20:43:18 +0000
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-01-06 08:22:46 +0330
commit93ef8c8080b0fb4a67d9ac496230bb850a4668c6 (patch)
tree6d1126ea714254eed4dca2d25677418cc4f6d543 /Userland/Libraries/LibMarkdown
parentfee43e35445883f9495434700518e75dfeb07d5b (diff)
downloadserenity-93ef8c8080b0fb4a67d9ac496230bb850a4668c6.zip
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.
Diffstat (limited to 'Userland/Libraries/LibMarkdown')
-rw-r--r--Userland/Libraries/LibMarkdown/Table.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/Userland/Libraries/LibMarkdown/Table.cpp b/Userland/Libraries/LibMarkdown/Table.cpp
index 995738f718..ff40867a88 100644
--- a/Userland/Libraries/LibMarkdown/Table.cpp
+++ b/Userland/Libraries/LibMarkdown/Table.cpp
@@ -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>");
}