1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:57:35 +00:00

LibMarkdown: Add start numbers for ordered lists

5. hey -> <ol start="5"><li>hey</li></ol>
This commit is contained in:
Peter Elliott 2021-09-29 23:19:56 -06:00 committed by Ali Mohammad Pur
parent a76a23e33b
commit 285038ebcf
2 changed files with 16 additions and 3 deletions

View file

@ -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);
}
}