mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 10:05:10 +00:00
LibMarkdown: Change MD Document parse API to return a RefPtr
Markdown documents are now obtained via the static Document::parse method, which returns a RefPtr<Document>, or nullptr on failure.
This commit is contained in:
parent
9a2177437b
commit
7ca562b200
8 changed files with 28 additions and 28 deletions
|
@ -75,25 +75,29 @@ static bool helper(Vector<StringView>::ConstIterator& lines, NonnullOwnPtrVector
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Document::parse(const StringView& str)
|
||||
RefPtr<Document> Document::parse(const StringView& str)
|
||||
{
|
||||
const Vector<StringView> lines_vec = str.lines();
|
||||
auto lines = lines_vec.begin();
|
||||
auto document = adopt(*new Document);
|
||||
auto& blocks = document->m_blocks;
|
||||
|
||||
while (true) {
|
||||
if (lines.is_end())
|
||||
return true;
|
||||
break;
|
||||
|
||||
if ((*lines).is_empty()) {
|
||||
++lines;
|
||||
continue;
|
||||
}
|
||||
|
||||
bool any = helper<List>(lines, m_blocks) || helper<Paragraph>(lines, m_blocks) || helper<CodeBlock>(lines, m_blocks) || helper<Heading>(lines, m_blocks);
|
||||
bool any = helper<List>(lines, blocks) || helper<Paragraph>(lines, blocks) || helper<CodeBlock>(lines, blocks) || helper<Heading>(lines, blocks);
|
||||
|
||||
if (!any)
|
||||
return false;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue