LibMarkdown: Match HTML formatting of Commonmark tests

This patch changes the HTML formatting (where to put newlines, etc...)
to better match commonmark's test cases. This has minimal effect of the
correctness of our markdown implementation, but makes it easier to test.

Changes:
 - Use <em> instead of <i>.
 - Newline before end of code block.
 - <hr /> instead of <hr>.
 - Newline before first list item.
 - Newline between lines of a paragraph.
 - Trim whitespace on lines of paragraphs.

 Tests passed: 33/652 -> 87/652
This commit is contained in:
Peter Elliott 2021-08-29 15:59:41 -07:00 committed by Andreas Kling
parent 8d2c04821f
commit dee84113ab
5 changed files with 8 additions and 8 deletions

View file

@ -36,7 +36,7 @@ String CodeBlock::render_to_html() const
if (style.strong)
builder.append("<b>");
if (style.emph)
builder.append("<i>");
builder.append("<em>");
if (style_language.is_empty())
builder.append("<code>");
@ -48,10 +48,10 @@ String CodeBlock::render_to_html() const
else
builder.append(escape_html_entities(m_code));
builder.append("</code>");
builder.append("\n</code>");
if (style.emph)
builder.append("</i>");
builder.append("</em>");
if (style.strong)
builder.append("</b>");

View file

@ -12,7 +12,7 @@ namespace Markdown {
String HorizontalRule::render_to_html() const
{
return "<hr>\n";
return "<hr />\n";
}
String HorizontalRule::render_for_terminal(size_t view_width) const

View file

@ -14,7 +14,7 @@ String List::render_to_html() const
StringBuilder builder;
const char* tag = m_is_ordered ? "ol" : "ul";
builder.appendff("<{}>", tag);
builder.appendff("<{}>\n", tag);
for (auto& item : m_items) {
builder.append("<li>");

View file

@ -16,9 +16,9 @@ String Paragraph::render_to_html() const
bool first = true;
for (auto& line : m_lines) {
if (!first)
builder.append(' ');
builder.append('\n');
first = false;
builder.append(line.text().render_to_html());
builder.append(line.text().render_to_html().trim(" \t"));
}
builder.append("</p>\n");
return builder.build();

View file

@ -44,7 +44,7 @@ String Text::render_to_html() const
bool Style::*flag;
};
TagAndFlag tags_and_flags[] = {
{ "i", &Style::emph },
{ "em", &Style::emph },
{ "b", &Style::strong },
{ "code", &Style::code }
};