Improvements for markdown parsing.

This commit is contained in:
James Grogan 2022-12-06 18:02:43 +00:00
parent fc44290e3f
commit 8705859115
40 changed files with 957 additions and 537 deletions

View file

@ -53,11 +53,11 @@ void XmlParser::processLine(const std::string& input)
void XmlParser::onChar(char c)
{
if(StringUtils::IsAlphaNumeric(c))
if(StringUtils::isAlphaNumeric(c))
{
onAlphaNumeric(c);
}
else if(StringUtils::IsSpace(c))
else if(StringUtils::isSpace(c))
{
onSpace(c);
}

View file

@ -98,10 +98,12 @@ XmlElement* XmlElement::getChild(std::size_t index) const
return mChildren[index].get();
}
std::string XmlElement::toString(unsigned depth) const
std::string XmlElement::toString(unsigned depth, bool keepInline) const
{
const auto prefix = std::string(2*depth, ' ');
std::string line_ending = keepInline ? "" : "\n";
auto content = prefix + "<" + getTagName();
for (std::size_t idx=0; idx< getNumAttributes(); idx++)
{
@ -112,7 +114,7 @@ std::string XmlElement::toString(unsigned depth) const
const auto num_children = getNumChildren();
if (num_children == 0 && getText().empty())
{
content += "/>\n";
content += "/>" + line_ending;
return content;
}
else
@ -127,18 +129,18 @@ std::string XmlElement::toString(unsigned depth) const
if (num_children>0)
{
content += "\n";
content += line_ending;
}
for (std::size_t idx=0; idx< getNumChildren(); idx++)
{
auto child = getChild(idx);
content += child->toString(depth+1);
content += child->toString(depth+1, keepInline);
}
if (num_children>0)
{
content += prefix;
}
content += "</" + getTagName() + ">\n";
content += "</" + getTagName() + ">" + line_ending;
return content;
}

View file

@ -34,7 +34,7 @@ public:
void setText(const std::string& text);
void setTagName(const std::string& tagName);
virtual std::string toString(unsigned depth = 0) const;
virtual std::string toString(unsigned depth = 0, bool keepInline = false) const;
protected:
std::string mTagName;