LibMarkdown: Add start numbers for ordered lists
5. hey -> <ol start="5"><li>hey</li></ol>
This commit is contained in:
parent
a76a23e33b
commit
285038ebcf
Notes:
sideshowbarker
2024-07-18 03:02:12 +09:00
Author: https://github.com/petelliott Commit: https://github.com/SerenityOS/serenity/commit/285038ebcfc Pull-request: https://github.com/SerenityOS/serenity/pull/10271 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/kleinesfilmroellchen
2 changed files with 16 additions and 3 deletions
|
@ -16,7 +16,12 @@ String List::render_to_html(bool) const
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
|
||||||
const char* tag = m_is_ordered ? "ol" : "ul";
|
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) {
|
for (auto& item : m_items) {
|
||||||
builder.append("<li>");
|
builder.append("<li>");
|
||||||
|
@ -59,6 +64,7 @@ OwnPtr<List> List::parse(LineIterator& lines)
|
||||||
|
|
||||||
bool is_tight = true;
|
bool is_tight = true;
|
||||||
bool has_trailing_blank_lines = false;
|
bool has_trailing_blank_lines = false;
|
||||||
|
size_t start_number = 1;
|
||||||
|
|
||||||
while (!lines.is_end()) {
|
while (!lines.is_end()) {
|
||||||
|
|
||||||
|
@ -85,6 +91,11 @@ OwnPtr<List> List::parse(LineIterator& lines)
|
||||||
continue;
|
continue;
|
||||||
if (ch == '.' || ch == ')')
|
if (ch == '.' || ch == ')')
|
||||||
if (i + 1 < line.length() && line[i + 1] == ' ') {
|
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;
|
appears_ordered = true;
|
||||||
offset = i + 1;
|
offset = i + 1;
|
||||||
}
|
}
|
||||||
|
@ -124,7 +135,7 @@ OwnPtr<List> List::parse(LineIterator& lines)
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return make<List>(move(items), is_ordered, is_tight);
|
return make<List>(move(items), is_ordered, is_tight, start_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,10 +15,11 @@ namespace Markdown {
|
||||||
|
|
||||||
class List final : public Block {
|
class List final : public Block {
|
||||||
public:
|
public:
|
||||||
List(Vector<OwnPtr<ContainerBlock>> items, bool is_ordered, bool is_tight)
|
List(Vector<OwnPtr<ContainerBlock>> items, bool is_ordered, bool is_tight, size_t start_number)
|
||||||
: m_items(move(items))
|
: m_items(move(items))
|
||||||
, m_is_ordered(is_ordered)
|
, m_is_ordered(is_ordered)
|
||||||
, m_is_tight(is_tight)
|
, m_is_tight(is_tight)
|
||||||
|
, m_start_number(start_number)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
virtual ~List() override { }
|
virtual ~List() override { }
|
||||||
|
@ -32,6 +33,7 @@ private:
|
||||||
Vector<OwnPtr<ContainerBlock>> m_items;
|
Vector<OwnPtr<ContainerBlock>> m_items;
|
||||||
bool m_is_ordered { false };
|
bool m_is_ordered { false };
|
||||||
bool m_is_tight { false };
|
bool m_is_tight { false };
|
||||||
|
size_t m_start_number { 1 };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue