|
@@ -25,13 +25,15 @@
|
|
*/
|
|
*/
|
|
|
|
|
|
#include <AK/StringBuilder.h>
|
|
#include <AK/StringBuilder.h>
|
|
-#include <LibMarkdown/MDCodeBlock.h>
|
|
|
|
-#include <LibMarkdown/MDDocument.h>
|
|
|
|
-#include <LibMarkdown/MDHeading.h>
|
|
|
|
-#include <LibMarkdown/MDList.h>
|
|
|
|
-#include <LibMarkdown/MDParagraph.h>
|
|
|
|
|
|
+#include <LibMarkdown/CodeBlock.h>
|
|
|
|
+#include <LibMarkdown/Document.h>
|
|
|
|
+#include <LibMarkdown/Heading.h>
|
|
|
|
+#include <LibMarkdown/List.h>
|
|
|
|
+#include <LibMarkdown/Paragraph.h>
|
|
|
|
|
|
-String MDDocument::render_to_html() const
|
|
|
|
|
|
+namespace Markdown {
|
|
|
|
+
|
|
|
|
+String Document::render_to_html() const
|
|
{
|
|
{
|
|
StringBuilder builder;
|
|
StringBuilder builder;
|
|
|
|
|
|
@@ -50,7 +52,7 @@ String MDDocument::render_to_html() const
|
|
return builder.build();
|
|
return builder.build();
|
|
}
|
|
}
|
|
|
|
|
|
-String MDDocument::render_for_terminal() const
|
|
|
|
|
|
+String Document::render_for_terminal() const
|
|
{
|
|
{
|
|
StringBuilder builder;
|
|
StringBuilder builder;
|
|
|
|
|
|
@@ -62,10 +64,10 @@ String MDDocument::render_for_terminal() const
|
|
return builder.build();
|
|
return builder.build();
|
|
}
|
|
}
|
|
|
|
|
|
-template<typename Block>
|
|
|
|
-static bool helper(Vector<StringView>::ConstIterator& lines, NonnullOwnPtrVector<MDBlock>& blocks)
|
|
|
|
|
|
+template<typename BlockType>
|
|
|
|
+static bool helper(Vector<StringView>::ConstIterator& lines, NonnullOwnPtrVector<Block>& blocks)
|
|
{
|
|
{
|
|
- NonnullOwnPtr<Block> block = make<Block>();
|
|
|
|
|
|
+ NonnullOwnPtr<BlockType> block = make<BlockType>();
|
|
bool success = block->parse(lines);
|
|
bool success = block->parse(lines);
|
|
if (!success)
|
|
if (!success)
|
|
return false;
|
|
return false;
|
|
@@ -73,7 +75,7 @@ static bool helper(Vector<StringView>::ConstIterator& lines, NonnullOwnPtrVector
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
-bool MDDocument::parse(const StringView& str)
|
|
|
|
|
|
+bool Document::parse(const StringView& str)
|
|
{
|
|
{
|
|
const Vector<StringView> lines_vec = str.lines();
|
|
const Vector<StringView> lines_vec = str.lines();
|
|
auto lines = lines_vec.begin();
|
|
auto lines = lines_vec.begin();
|
|
@@ -87,9 +89,11 @@ bool MDDocument::parse(const StringView& str)
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
- bool any = helper<MDList>(lines, m_blocks) || helper<MDParagraph>(lines, m_blocks) || helper<MDCodeBlock>(lines, m_blocks) || helper<MDHeading>(lines, m_blocks);
|
|
|
|
|
|
+ bool any = helper<List>(lines, m_blocks) || helper<Paragraph>(lines, m_blocks) || helper<CodeBlock>(lines, m_blocks) || helper<Heading>(lines, m_blocks);
|
|
|
|
|
|
if (!any)
|
|
if (!any)
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+}
|