diff options
author | Peter Elliott <pelliott@ualberta.ca> | 2021-09-29 23:19:56 -0600 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-10-05 13:27:25 +0330 |
commit | 285038ebcfc1cf1f46de098d8ca95f615887be94 (patch) | |
tree | 77c9a84ad6ec174a330e61388ee552e6bda88013 /Userland/Libraries/LibMarkdown/List.cpp | |
parent | a76a23e33b1038687b644c33dff6e5c8955f7230 (diff) | |
download | serenity-285038ebcfc1cf1f46de098d8ca95f615887be94.zip |
LibMarkdown: Add start numbers for ordered lists
5. hey -> <ol start="5"><li>hey</li></ol>
Diffstat (limited to 'Userland/Libraries/LibMarkdown/List.cpp')
-rw-r--r-- | Userland/Libraries/LibMarkdown/List.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/Userland/Libraries/LibMarkdown/List.cpp b/Userland/Libraries/LibMarkdown/List.cpp index 5ddc8472e1..0b4df3584c 100644 --- a/Userland/Libraries/LibMarkdown/List.cpp +++ b/Userland/Libraries/LibMarkdown/List.cpp @@ -16,7 +16,12 @@ String List::render_to_html(bool) const StringBuilder builder; const char* tag = m_is_ordered ? "ol" : "ul"; - builder.appendff("<{}>\n", tag); + builder.appendff("<{}", tag); + + if (m_start_number != 1) + builder.appendff(" start=\"{}\"", m_start_number); + + builder.append(">\n"); for (auto& item : m_items) { builder.append("<li>"); @@ -59,6 +64,7 @@ OwnPtr<List> List::parse(LineIterator& lines) bool is_tight = true; bool has_trailing_blank_lines = false; + size_t start_number = 1; while (!lines.is_end()) { @@ -85,6 +91,11 @@ OwnPtr<List> List::parse(LineIterator& lines) continue; if (ch == '.' || ch == ')') if (i + 1 < line.length() && line[i + 1] == ' ') { + auto maybe_start_number = line.substring_view(offset, i - offset).to_uint<size_t>(); + if (!maybe_start_number.has_value()) + break; + if (first) + start_number = maybe_start_number.value(); appears_ordered = true; offset = i + 1; } @@ -124,7 +135,7 @@ OwnPtr<List> List::parse(LineIterator& lines) first = false; } - return make<List>(move(items), is_ordered, is_tight); + return make<List>(move(items), is_ordered, is_tight, start_number); } } |