Compare commits

..

No commits in common. "0ef0500fe8037f87efae460fe9ec2de9ddb272b9" and "d863b931326cff80142f6f5a308b27328c2efc68" have entirely different histories.

3 changed files with 16 additions and 63 deletions

View File

@ -15,8 +15,4 @@ this is too far`
## **Hello world**
### hello *world*
# ***This is both!***
###### This is neither
### hello world

View File

@ -108,15 +108,25 @@ std::unique_ptr<Node> Parser::ParseHeading() {
ConsumeWhiteSpace();
// This should call parse inline
auto text_nodes = ParseInline();
for (auto &text_node : text_nodes) {
node->AddChild(std::move(text_node));
std::string str;
while (!IsEOF()) {
c = Peek();
// We can stop as soon as we see a new line. Headings are single line blocks
if (c == '\n')
break;
// If a newline, use a space instead
str += c;
Consume();
}
if (node->IsEmpty())
// BUG: Why do we need to check this?
if (str == "")
return nullptr;
auto text_node = std::make_unique<TextNode>(str);
node->AddChild(std::move(text_node));
return node;
}
@ -169,54 +179,6 @@ vector<std::unique_ptr<Node>> Parser::ParseInline() {
return nodes;
}
vector<std::unique_ptr<Node>> Parser::ParseInlineHeading() {
vector<std::unique_ptr<Node>> nodes;
string str;
while (!IsEOF()) {
char c = Peek();
// We can stop as soon as we see a new line. Headings are single line blocks
if (c == '\n')
break;
if (c == '*' && Peek(1) == '*' && Peek(2) == '*') {
PushTextNode(nodes, str);
auto node = ParseBoldItalic();
if (!node->IsEmpty())
nodes.push_back(std::move(node));
continue;
} else if (c == '*' && Peek(1) == '*') {
PushTextNode(nodes, str);
auto node = ParseBold();
if (!node->IsEmpty())
nodes.push_back(std::move(node));
continue;
} else if (c == '*') {
PushTextNode(nodes, str);
auto node = ParseItalic();
if (!node->IsEmpty())
nodes.push_back(std::move(node));
continue;
}
if (c == '`') {
PushTextNode(nodes, str);
auto node = ParseCode();
if (!node->IsEmpty())
nodes.push_back(std::move(node));
continue;
}
// If a newline, use a space instead
str += (c == '\n' ? ' ' : c);
Consume();
}
// Push the last node, if the string is not empty
PushTextNode(nodes, str);
return nodes;
}
std::unique_ptr<Node> Parser::ParseItalic() {
string str;
Consume(1);

View File

@ -117,15 +117,10 @@ private:
// Working input content
string content;
// TODO: Document these methods, no more magic methods :)
std::unique_ptr<Node> ParseParagraph();
std::unique_ptr<Node> ParseHeading();
vector<std::unique_ptr<Node>> ParseInline();
// The only difference is the exit condition
vector<std::unique_ptr<Node>> ParseInlineHeading();
void PushTextNode(vector<std::unique_ptr<Node>> &nodes, string &str);
std::unique_ptr<Node> ParseItalic();