diff options
author | Peter Elliott <pelliott@ualberta.ca> | 2021-08-29 15:59:41 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-31 16:53:51 +0200 |
commit | dee84113abba402a87b9e0440bfaa10fd67fe909 (patch) | |
tree | 4fe1cb73cc39195431f2d4a814df314810ded8a7 /Userland/Libraries | |
parent | 8d2c04821ff751fd6971154fe062392ae5116c33 (diff) | |
download | serenity-dee84113abba402a87b9e0440bfaa10fd67fe909.zip |
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
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibMarkdown/CodeBlock.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibMarkdown/HorizontalRule.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibMarkdown/List.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibMarkdown/Paragraph.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibMarkdown/Text.cpp | 2 |
5 files changed, 8 insertions, 8 deletions
diff --git a/Userland/Libraries/LibMarkdown/CodeBlock.cpp b/Userland/Libraries/LibMarkdown/CodeBlock.cpp index 58b5895f91..3f8d80a7f4 100644 --- a/Userland/Libraries/LibMarkdown/CodeBlock.cpp +++ b/Userland/Libraries/LibMarkdown/CodeBlock.cpp @@ -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>"); diff --git a/Userland/Libraries/LibMarkdown/HorizontalRule.cpp b/Userland/Libraries/LibMarkdown/HorizontalRule.cpp index 1fb7cc710b..190380c175 100644 --- a/Userland/Libraries/LibMarkdown/HorizontalRule.cpp +++ b/Userland/Libraries/LibMarkdown/HorizontalRule.cpp @@ -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 diff --git a/Userland/Libraries/LibMarkdown/List.cpp b/Userland/Libraries/LibMarkdown/List.cpp index b23baed187..8162090f00 100644 --- a/Userland/Libraries/LibMarkdown/List.cpp +++ b/Userland/Libraries/LibMarkdown/List.cpp @@ -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>"); diff --git a/Userland/Libraries/LibMarkdown/Paragraph.cpp b/Userland/Libraries/LibMarkdown/Paragraph.cpp index d252fae464..c90e016b11 100644 --- a/Userland/Libraries/LibMarkdown/Paragraph.cpp +++ b/Userland/Libraries/LibMarkdown/Paragraph.cpp @@ -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(); diff --git a/Userland/Libraries/LibMarkdown/Text.cpp b/Userland/Libraries/LibMarkdown/Text.cpp index b399021589..ab61792142 100644 --- a/Userland/Libraries/LibMarkdown/Text.cpp +++ b/Userland/Libraries/LibMarkdown/Text.cpp @@ -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 } }; |