Some repairs for md_parser and template engine.
This commit is contained in:
parent
8705859115
commit
22157169c0
14 changed files with 180 additions and 159 deletions
|
@ -17,7 +17,7 @@ public:
|
|||
|
||||
std::string toString(unsigned depth = 0, bool keepInline = false) const override
|
||||
{
|
||||
const auto prefix = std::string(2*depth, ' ');
|
||||
return prefix + getText();
|
||||
|
||||
return getText();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -34,9 +34,18 @@ std::vector<MarkdownLink*> MarkdownDocument::getAllLinks() const
|
|||
{
|
||||
if (element->getType() == MarkdownElement::Type::PARAGRAPH)
|
||||
{
|
||||
auto para_links = dynamic_cast<MarkdownParagraph*>(element.get())->getAllLinks();
|
||||
auto para_links = dynamic_cast<MarkdownElementWithChildren*>(element.get())->getAllLinks();
|
||||
links.insert(links.end(), para_links.begin(), para_links.end());
|
||||
}
|
||||
else if (element->getType() == MarkdownElement::Type::BULLET_LIST)
|
||||
{
|
||||
auto bullet_list = dynamic_cast<MarkdownBulletList*>(element.get());
|
||||
for(unsigned idx=0; idx<bullet_list->getNumChildren(); idx++)
|
||||
{
|
||||
auto para_links = bullet_list->getChild(idx)->getAllLinks();
|
||||
links.insert(links.end(), para_links.begin(), para_links.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
return links;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include "StringUtils.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
static constexpr char MULTILINE_QUOTE_DELIMITER[]{"```"};
|
||||
static constexpr char HEADING_DELIMITER{'#'};
|
||||
|
@ -151,12 +150,10 @@ void MarkdownParser::onTextSpanFinished()
|
|||
{
|
||||
if (mWorkingTextSpan)
|
||||
{
|
||||
std::cout << "Adding to existing text span: " << std::endl;
|
||||
mWorkingTextSpan->appendTextContent(mWorkingLine);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Adding new text span: " << mWorkingLine << std::endl;
|
||||
auto text_span = std::make_unique<MarkdownTextSpan>();
|
||||
text_span->addLine(mWorkingLine);
|
||||
mWorkingTextSpan = text_span.get();
|
||||
|
@ -183,7 +180,6 @@ void MarkdownParser::processLine(const std::string& line)
|
|||
|
||||
if (!mWorkingElement)
|
||||
{
|
||||
std::cout << "Adding new paragraph " << std::endl;
|
||||
auto paragraph = std::make_unique<MarkdownParagraph>();
|
||||
mWorkingElement = paragraph.get();
|
||||
mMarkdownDocument->addElement(std::move(paragraph));
|
||||
|
@ -341,7 +337,6 @@ void MarkdownParser::onFoundBulletItem(const std::string& line)
|
|||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Starting new bullet list" << std::endl;
|
||||
auto bullet_list = std::make_unique<MarkdownBulletList>();
|
||||
mWorkingBulletList = bullet_list.get();
|
||||
|
||||
|
@ -350,15 +345,13 @@ void MarkdownParser::onFoundBulletItem(const std::string& line)
|
|||
auto bullet_item = std::make_unique<MarkdownBulletItem>();
|
||||
mWorkingElement = bullet_item.get();
|
||||
mWorkingBulletList->addChild(std::move(bullet_item));
|
||||
|
||||
processLine(StringUtils::removeUpTo(line, "*"));
|
||||
}
|
||||
processLine(StringUtils::removeUpTo(line, "*"));
|
||||
}
|
||||
}
|
||||
|
||||
void MarkdownParser::onSectionFinished()
|
||||
{
|
||||
std::cout << "Section is finished" << std::endl;
|
||||
mWorkingElement = nullptr;
|
||||
mWorkingBulletList = nullptr;
|
||||
mWorkingTextSpan = nullptr;
|
||||
|
@ -373,36 +366,29 @@ std::unique_ptr<MarkdownDocument> MarkdownParser::run(const std::string& content
|
|||
|
||||
while (std::getline(ss, line, '\n'))
|
||||
{
|
||||
std::cout << "Processing line " << line << std::endl;
|
||||
if (StringUtils::isWhitespaceOnly(line))
|
||||
{
|
||||
std::cout << "Is whitespace only " << std::endl;
|
||||
onEmptyLine();
|
||||
continue;
|
||||
}
|
||||
else if (startsWithMultiLineQuote(line))
|
||||
{
|
||||
std::cout << "Found multiline quote" << std::endl;
|
||||
onFoundMultiLineQuote(line);
|
||||
}
|
||||
else if (auto result = startsWithCustomMultilineBlock(line); result >= 0)
|
||||
{
|
||||
std::cout << "Found custom multiline" << std::endl;
|
||||
onFoundCustomMultiLineBlock(line, result);
|
||||
}
|
||||
else if (startsWithHeading(line))
|
||||
{
|
||||
std::cout << "Found heading" << std::endl;
|
||||
onFoundHeading(line);
|
||||
}
|
||||
else if(startsWithBulletItem(line))
|
||||
{
|
||||
std::cout << "Found bulletitem" << std::endl;
|
||||
onFoundBulletItem(line);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Found nothing - process line" << std::endl;
|
||||
processLine(line);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,11 +28,6 @@ private:
|
|||
|
||||
bool isInMultilineBlock() const;
|
||||
|
||||
bool startsWithMultiLineQuote(const std::string& line) const;
|
||||
int startsWithCustomMultilineBlock(const std::string& line) const;
|
||||
bool startsWithHeading(const std::string& line) const;
|
||||
bool startsWithBulletItem(const std::string& line) const;
|
||||
|
||||
void onFoundMultiLineQuote(const std::string& line);
|
||||
void onFoundCustomMultiLineBlock(const std::string& line, unsigned blockSlot);
|
||||
void onFoundHeading(const std::string& line);
|
||||
|
@ -44,6 +39,11 @@ private:
|
|||
|
||||
void processLine(const std::string& line);
|
||||
|
||||
bool startsWithMultiLineQuote(const std::string& line) const;
|
||||
int startsWithCustomMultilineBlock(const std::string& line) const;
|
||||
bool startsWithHeading(const std::string& line) const;
|
||||
bool startsWithBulletItem(const std::string& line) const;
|
||||
|
||||
unsigned mCustomDelimiterIndex{0};
|
||||
std::vector<std::string> mCustomMultilineDelimiters;
|
||||
std::vector<std::string> mCustomInlineDelimiters;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue