1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:48:11 +00:00

LibMarkdown: Change internal MD API to return OwnPtrs

Previously, all Markdown blocks had a virtual parse method which has
been swapped out for a static parse method returning an OwnPtr of
that block's type.

The Text class also now has a static parse method that will return an
Optional<Text>.
This commit is contained in:
FalseHonesty 2020-05-18 16:58:00 -04:00 committed by Andreas Kling
parent 7ca562b200
commit 20faa93cb0
15 changed files with 110 additions and 64 deletions

View file

@ -105,16 +105,16 @@ String CodeBlock::render_for_terminal() const
return builder.build();
}
bool CodeBlock::parse(Vector<StringView>::ConstIterator& lines)
OwnPtr<CodeBlock> CodeBlock::parse(Vector<StringView>::ConstIterator& lines)
{
if (lines.is_end())
return false;
return nullptr;
constexpr auto tick_tick_tick = "```";
StringView line = *lines;
if (!line.starts_with(tick_tick_tick))
return false;
return nullptr;
// Our Markdown extension: we allow
// specifying a style and a language
@ -128,8 +128,9 @@ bool CodeBlock::parse(Vector<StringView>::ConstIterator& lines)
// and if possible syntax-highlighted
// as appropriate for a shell script.
StringView style_spec = line.substring_view(3, line.length() - 3);
bool success = m_style_spec.parse(style_spec);
ASSERT(success);
auto spec = Text::parse(style_spec);
if (!spec.has_value())
return nullptr;
++lines;
@ -149,8 +150,7 @@ bool CodeBlock::parse(Vector<StringView>::ConstIterator& lines)
first = false;
}
m_code = builder.build();
return true;
return make<CodeBlock>(move(spec.value()), builder.build());
}
}