mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-12 12:32:21 +00:00
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:
parent
8d2c04821f
commit
dee84113ab
Notes:
sideshowbarker
2024-07-18 04:59:27 +09:00
Author: https://github.com/petelliott
Commit: dee84113ab
Pull-request: https://github.com/SerenityOS/serenity/pull/9679
Reviewed-by: https://github.com/ADKaster ✅
5 changed files with 8 additions and 8 deletions
|
@ -36,7 +36,7 @@ String CodeBlock::render_to_html() const
|
||||||
if (style.strong)
|
if (style.strong)
|
||||||
builder.append("<b>");
|
builder.append("<b>");
|
||||||
if (style.emph)
|
if (style.emph)
|
||||||
builder.append("<i>");
|
builder.append("<em>");
|
||||||
|
|
||||||
if (style_language.is_empty())
|
if (style_language.is_empty())
|
||||||
builder.append("<code>");
|
builder.append("<code>");
|
||||||
|
@ -48,10 +48,10 @@ String CodeBlock::render_to_html() const
|
||||||
else
|
else
|
||||||
builder.append(escape_html_entities(m_code));
|
builder.append(escape_html_entities(m_code));
|
||||||
|
|
||||||
builder.append("</code>");
|
builder.append("\n</code>");
|
||||||
|
|
||||||
if (style.emph)
|
if (style.emph)
|
||||||
builder.append("</i>");
|
builder.append("</em>");
|
||||||
if (style.strong)
|
if (style.strong)
|
||||||
builder.append("</b>");
|
builder.append("</b>");
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace Markdown {
|
||||||
|
|
||||||
String HorizontalRule::render_to_html() const
|
String HorizontalRule::render_to_html() const
|
||||||
{
|
{
|
||||||
return "<hr>\n";
|
return "<hr />\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
String HorizontalRule::render_for_terminal(size_t view_width) const
|
String HorizontalRule::render_for_terminal(size_t view_width) const
|
||||||
|
|
|
@ -14,7 +14,7 @@ String List::render_to_html() const
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
|
||||||
const char* tag = m_is_ordered ? "ol" : "ul";
|
const char* tag = m_is_ordered ? "ol" : "ul";
|
||||||
builder.appendff("<{}>", tag);
|
builder.appendff("<{}>\n", tag);
|
||||||
|
|
||||||
for (auto& item : m_items) {
|
for (auto& item : m_items) {
|
||||||
builder.append("<li>");
|
builder.append("<li>");
|
||||||
|
|
|
@ -16,9 +16,9 @@ String Paragraph::render_to_html() const
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto& line : m_lines) {
|
for (auto& line : m_lines) {
|
||||||
if (!first)
|
if (!first)
|
||||||
builder.append(' ');
|
builder.append('\n');
|
||||||
first = false;
|
first = false;
|
||||||
builder.append(line.text().render_to_html());
|
builder.append(line.text().render_to_html().trim(" \t"));
|
||||||
}
|
}
|
||||||
builder.append("</p>\n");
|
builder.append("</p>\n");
|
||||||
return builder.build();
|
return builder.build();
|
||||||
|
|
|
@ -44,7 +44,7 @@ String Text::render_to_html() const
|
||||||
bool Style::*flag;
|
bool Style::*flag;
|
||||||
};
|
};
|
||||||
TagAndFlag tags_and_flags[] = {
|
TagAndFlag tags_and_flags[] = {
|
||||||
{ "i", &Style::emph },
|
{ "em", &Style::emph },
|
||||||
{ "b", &Style::strong },
|
{ "b", &Style::strong },
|
||||||
{ "code", &Style::code }
|
{ "code", &Style::code }
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue