stuff-from-scratch/src/web/markdown/MarkdownParser.h
2022-12-01 17:13:54 +00:00

56 lines
1 KiB
C++

#pragma once
#include <memory>
#include <string>
class MarkdownDocument;
class MarkdownParagraph;
class MarkdownParser
{
enum class DocumentState
{
NONE,
IN_MULTILINEQUOTE
};
enum class LineState
{
NONE,
IN_HEADING,
IN_INLINEQUOTE,
IN_MULTILINE_TAG
};
public:
MarkdownParser();
~MarkdownParser();
std::unique_ptr<MarkdownDocument> run(const std::string& content);
private:
void processLine();
void onMultilineQuote();
void onInlineQuote();
void onHeading(unsigned level);
void onEmptyLine();
void onNewParagraph();
void onTextSpan();
std::pair<unsigned, bool> onTick(unsigned tickCount);
std::string mWorkingLine;
std::string mLineContent;
std::string mDocumentContent;
std::string mMultilineTag;
LineState mLineState {LineState::NONE};
DocumentState mDocumentState {DocumentState::NONE};
std::unique_ptr<MarkdownParagraph> mWorkingParagraph{nullptr};
std::unique_ptr<MarkdownDocument> mMarkdownDocument;
};