mirror of
https://github.com/progsource/maddy.git
synced 2026-03-25 07:50:39 +01:00
chore: Add clang-format
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "maddy/parserconfig.h"
|
||||
@@ -56,8 +56,12 @@ public:
|
||||
*
|
||||
* Check https://github.com/progsource/maddy/blob/master/CHANGELOG.md
|
||||
* for the changelog.
|
||||
*/
|
||||
static const std::string& version() { static const std::string v = "1.3.0"; return v; }
|
||||
*/
|
||||
static const std::string& version()
|
||||
{
|
||||
static const std::string v = "1.3.0";
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* ctor
|
||||
@@ -66,8 +70,7 @@ public:
|
||||
*
|
||||
* @method
|
||||
*/
|
||||
Parser(std::shared_ptr<ParserConfig> config = nullptr)
|
||||
: config(config)
|
||||
Parser(std::shared_ptr<ParserConfig> config = nullptr) : config(config)
|
||||
{
|
||||
// deprecated backward compatibility
|
||||
// will be removed in 1.4.0 latest including the booleans
|
||||
@@ -80,66 +83,50 @@ public:
|
||||
this->config->enabledParsers |= maddy::types::HTML_PARSER;
|
||||
}
|
||||
|
||||
if (
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::BREAKLINE_PARSER) != 0
|
||||
)
|
||||
if (!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::BREAKLINE_PARSER) != 0)
|
||||
{
|
||||
this->breakLineParser = std::make_shared<BreakLineParser>();
|
||||
}
|
||||
|
||||
if (
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::EMPHASIZED_PARSER) != 0
|
||||
)
|
||||
if (!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::EMPHASIZED_PARSER) != 0)
|
||||
{
|
||||
this->emphasizedParser = std::make_shared<EmphasizedParser>();
|
||||
}
|
||||
|
||||
if (
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::IMAGE_PARSER) != 0
|
||||
)
|
||||
if (!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::IMAGE_PARSER) != 0)
|
||||
{
|
||||
this->imageParser = std::make_shared<ImageParser>();
|
||||
}
|
||||
|
||||
if (
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::INLINE_CODE_PARSER) != 0
|
||||
)
|
||||
if (!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::INLINE_CODE_PARSER) != 0)
|
||||
{
|
||||
this->inlineCodeParser = std::make_shared<InlineCodeParser>();
|
||||
}
|
||||
|
||||
if (
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::ITALIC_PARSER) != 0
|
||||
)
|
||||
if (!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::ITALIC_PARSER) != 0)
|
||||
{
|
||||
this->italicParser = std::make_shared<ItalicParser>();
|
||||
}
|
||||
|
||||
if (
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::LINK_PARSER) != 0
|
||||
)
|
||||
if (!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::LINK_PARSER) != 0)
|
||||
{
|
||||
this->linkParser = std::make_shared<LinkParser>();
|
||||
}
|
||||
|
||||
if (
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::STRIKETHROUGH_PARSER) != 0
|
||||
)
|
||||
if (!this->config || (this->config->enabledParsers &
|
||||
maddy::types::STRIKETHROUGH_PARSER) != 0)
|
||||
{
|
||||
this->strikeThroughParser = std::make_shared<StrikeThroughParser>();
|
||||
}
|
||||
|
||||
if (
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::STRONG_PARSER) != 0
|
||||
)
|
||||
if (!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::STRONG_PARSER) != 0)
|
||||
{
|
||||
this->strongParser = std::make_shared<StrongParser>();
|
||||
}
|
||||
@@ -152,8 +139,7 @@ public:
|
||||
* @param {const std::istream&} markdown
|
||||
* @return {std::string} HTML
|
||||
*/
|
||||
std::string
|
||||
Parse(std::istream& markdown) const
|
||||
std::string Parse(std::istream& markdown) const
|
||||
{
|
||||
std::string result = "";
|
||||
std::shared_ptr<BlockParser> currentBlockParser = nullptr;
|
||||
@@ -204,8 +190,7 @@ private:
|
||||
std::shared_ptr<StrongParser> strongParser;
|
||||
|
||||
// block parser have to run before
|
||||
void
|
||||
runLineParser(std::string& line) const
|
||||
void runLineParser(std::string& line) const
|
||||
{
|
||||
// Attention! ImageParser has to be before LinkParser
|
||||
if (this->imageParser)
|
||||
@@ -250,167 +235,114 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<BlockParser>
|
||||
getBlockParserForLine(const std::string& line) const
|
||||
std::shared_ptr<BlockParser> getBlockParserForLine(const std::string& line
|
||||
) const
|
||||
{
|
||||
std::shared_ptr<BlockParser> parser;
|
||||
|
||||
if (
|
||||
(
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::CODE_BLOCK_PARSER) != 0
|
||||
) &&
|
||||
maddy::CodeBlockParser::IsStartingLine(line)
|
||||
)
|
||||
if ((!this->config || (this->config->enabledParsers &
|
||||
maddy::types::CODE_BLOCK_PARSER) != 0) &&
|
||||
maddy::CodeBlockParser::IsStartingLine(line))
|
||||
{
|
||||
parser = std::make_shared<maddy::CodeBlockParser>(
|
||||
nullptr,
|
||||
nullptr
|
||||
);
|
||||
parser = std::make_shared<maddy::CodeBlockParser>(nullptr, nullptr);
|
||||
}
|
||||
else if (
|
||||
this->config &&
|
||||
(this->config->enabledParsers & maddy::types::LATEX_BLOCK_PARSER) != 0 &&
|
||||
maddy::LatexBlockParser::IsStartingLine(line)
|
||||
)
|
||||
else if (this->config &&
|
||||
(this->config->enabledParsers & maddy::types::LATEX_BLOCK_PARSER
|
||||
) != 0 &&
|
||||
maddy::LatexBlockParser::IsStartingLine(line))
|
||||
{
|
||||
parser = std::make_shared<LatexBlockParser>(
|
||||
nullptr,
|
||||
nullptr
|
||||
);
|
||||
parser = std::make_shared<LatexBlockParser>(nullptr, nullptr);
|
||||
}
|
||||
else if (
|
||||
(
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::HEADLINE_PARSER) != 0
|
||||
) &&
|
||||
maddy::HeadlineParser::IsStartingLine(line)
|
||||
)
|
||||
else if ((!this->config || (this->config->enabledParsers &
|
||||
maddy::types::HEADLINE_PARSER) != 0) &&
|
||||
maddy::HeadlineParser::IsStartingLine(line))
|
||||
{
|
||||
if (!this->config || this->config->isHeadlineInlineParsingEnabled)
|
||||
{
|
||||
parser = std::make_shared<maddy::HeadlineParser>(
|
||||
[this](std::string& line){ this->runLineParser(line); },
|
||||
[this](std::string& line) { this->runLineParser(line); },
|
||||
nullptr,
|
||||
true
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser = std::make_shared<maddy::HeadlineParser>(
|
||||
nullptr,
|
||||
nullptr,
|
||||
false
|
||||
);
|
||||
parser =
|
||||
std::make_shared<maddy::HeadlineParser>(nullptr, nullptr, false);
|
||||
}
|
||||
}
|
||||
else if (
|
||||
(
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::HORIZONTAL_LINE_PARSER) != 0
|
||||
) &&
|
||||
maddy::HorizontalLineParser::IsStartingLine(line)
|
||||
)
|
||||
else if ((!this->config || (this->config->enabledParsers &
|
||||
maddy::types::HORIZONTAL_LINE_PARSER) != 0) &&
|
||||
maddy::HorizontalLineParser::IsStartingLine(line))
|
||||
{
|
||||
parser = std::make_shared<maddy::HorizontalLineParser>(
|
||||
nullptr,
|
||||
nullptr
|
||||
);
|
||||
parser = std::make_shared<maddy::HorizontalLineParser>(nullptr, nullptr);
|
||||
}
|
||||
else if (
|
||||
(
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::QUOTE_PARSER) != 0
|
||||
) &&
|
||||
maddy::QuoteParser::IsStartingLine(line)
|
||||
)
|
||||
else if ((!this->config || (this->config->enabledParsers &
|
||||
maddy::types::QUOTE_PARSER) != 0) &&
|
||||
maddy::QuoteParser::IsStartingLine(line))
|
||||
{
|
||||
parser = std::make_shared<maddy::QuoteParser>(
|
||||
[this](std::string& line){ this->runLineParser(line); },
|
||||
[this](const std::string& line){ return this->getBlockParserForLine(line); }
|
||||
[this](std::string& line) { this->runLineParser(line); },
|
||||
[this](const std::string& line)
|
||||
{ return this->getBlockParserForLine(line); }
|
||||
);
|
||||
}
|
||||
else if (
|
||||
(
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::TABLE_PARSER) != 0
|
||||
) &&
|
||||
maddy::TableParser::IsStartingLine(line)
|
||||
)
|
||||
else if ((!this->config || (this->config->enabledParsers &
|
||||
maddy::types::TABLE_PARSER) != 0) &&
|
||||
maddy::TableParser::IsStartingLine(line))
|
||||
{
|
||||
parser = std::make_shared<maddy::TableParser>(
|
||||
[this](std::string& line){ this->runLineParser(line); },
|
||||
nullptr
|
||||
[this](std::string& line) { this->runLineParser(line); }, nullptr
|
||||
);
|
||||
}
|
||||
else if (
|
||||
(
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::CHECKLIST_PARSER) != 0
|
||||
) &&
|
||||
maddy::ChecklistParser::IsStartingLine(line)
|
||||
)
|
||||
else if ((!this->config || (this->config->enabledParsers &
|
||||
maddy::types::CHECKLIST_PARSER) != 0) &&
|
||||
maddy::ChecklistParser::IsStartingLine(line))
|
||||
{
|
||||
parser = this->createChecklistParser();
|
||||
}
|
||||
else if (
|
||||
(
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::ORDERED_LIST_PARSER) != 0
|
||||
) &&
|
||||
maddy::OrderedListParser::IsStartingLine(line)
|
||||
)
|
||||
else if ((!this->config || (this->config->enabledParsers &
|
||||
maddy::types::ORDERED_LIST_PARSER) != 0) &&
|
||||
maddy::OrderedListParser::IsStartingLine(line))
|
||||
{
|
||||
parser = this->createOrderedListParser();
|
||||
}
|
||||
else if (
|
||||
(
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::UNORDERED_LIST_PARSER) != 0
|
||||
) &&
|
||||
maddy::UnorderedListParser::IsStartingLine(line)
|
||||
)
|
||||
else if ((!this->config || (this->config->enabledParsers &
|
||||
maddy::types::UNORDERED_LIST_PARSER) != 0) &&
|
||||
maddy::UnorderedListParser::IsStartingLine(line))
|
||||
{
|
||||
parser = this->createUnorderedListParser();
|
||||
}
|
||||
else if (
|
||||
this->config &&
|
||||
(this->config->enabledParsers & maddy::types::HTML_PARSER) != 0 &&
|
||||
maddy::HtmlParser::IsStartingLine(line)
|
||||
)
|
||||
else if (this->config &&
|
||||
(this->config->enabledParsers & maddy::types::HTML_PARSER) != 0 &&
|
||||
maddy::HtmlParser::IsStartingLine(line))
|
||||
{
|
||||
parser = std::make_shared<maddy::HtmlParser>(nullptr, nullptr);
|
||||
}
|
||||
else if (
|
||||
maddy::ParagraphParser::IsStartingLine(line)
|
||||
)
|
||||
else if (maddy::ParagraphParser::IsStartingLine(line))
|
||||
{
|
||||
parser = std::make_shared<maddy::ParagraphParser>(
|
||||
[this](std::string& line){ this->runLineParser(line); },
|
||||
[this](std::string& line) { this->runLineParser(line); },
|
||||
nullptr,
|
||||
(!this->config || (this->config->enabledParsers & maddy::types::PARAGRAPH_PARSER) != 0)
|
||||
(!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::PARAGRAPH_PARSER) != 0)
|
||||
);
|
||||
}
|
||||
|
||||
return parser;
|
||||
}
|
||||
|
||||
std::shared_ptr<BlockParser>
|
||||
createChecklistParser() const
|
||||
std::shared_ptr<BlockParser> createChecklistParser() const
|
||||
{
|
||||
return std::make_shared<maddy::ChecklistParser>(
|
||||
[this](std::string& line){ this->runLineParser(line); },
|
||||
[this](std::string& line) { this->runLineParser(line); },
|
||||
[this](const std::string& line)
|
||||
{
|
||||
std::shared_ptr<BlockParser> parser;
|
||||
|
||||
if (
|
||||
(
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::CHECKLIST_PARSER) != 0
|
||||
) &&
|
||||
maddy::ChecklistParser::IsStartingLine(line)
|
||||
)
|
||||
if ((!this->config || (this->config->enabledParsers &
|
||||
maddy::types::CHECKLIST_PARSER) != 0) &&
|
||||
maddy::ChecklistParser::IsStartingLine(line))
|
||||
{
|
||||
parser = this->createChecklistParser();
|
||||
}
|
||||
@@ -420,32 +352,24 @@ private:
|
||||
);
|
||||
}
|
||||
|
||||
std::shared_ptr<BlockParser>
|
||||
createOrderedListParser() const
|
||||
std::shared_ptr<BlockParser> createOrderedListParser() const
|
||||
{
|
||||
return std::make_shared<maddy::OrderedListParser>(
|
||||
[this](std::string& line){ this->runLineParser(line); },
|
||||
[this](std::string& line) { this->runLineParser(line); },
|
||||
[this](const std::string& line)
|
||||
{
|
||||
std::shared_ptr<BlockParser> parser;
|
||||
|
||||
if (
|
||||
(
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::ORDERED_LIST_PARSER) != 0
|
||||
) &&
|
||||
maddy::OrderedListParser::IsStartingLine(line)
|
||||
)
|
||||
if ((!this->config || (this->config->enabledParsers &
|
||||
maddy::types::ORDERED_LIST_PARSER) != 0) &&
|
||||
maddy::OrderedListParser::IsStartingLine(line))
|
||||
{
|
||||
parser = this->createOrderedListParser();
|
||||
}
|
||||
else if (
|
||||
(
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::UNORDERED_LIST_PARSER) != 0
|
||||
) &&
|
||||
maddy::UnorderedListParser::IsStartingLine(line)
|
||||
)
|
||||
else if ((!this->config || (this->config->enabledParsers &
|
||||
maddy::types::UNORDERED_LIST_PARSER) != 0
|
||||
) &&
|
||||
maddy::UnorderedListParser::IsStartingLine(line))
|
||||
{
|
||||
parser = this->createUnorderedListParser();
|
||||
}
|
||||
@@ -455,32 +379,24 @@ private:
|
||||
);
|
||||
}
|
||||
|
||||
std::shared_ptr<BlockParser>
|
||||
createUnorderedListParser() const
|
||||
std::shared_ptr<BlockParser> createUnorderedListParser() const
|
||||
{
|
||||
return std::make_shared<maddy::UnorderedListParser>(
|
||||
[this](std::string& line){ this->runLineParser(line); },
|
||||
[this](std::string& line) { this->runLineParser(line); },
|
||||
[this](const std::string& line)
|
||||
{
|
||||
std::shared_ptr<BlockParser> parser;
|
||||
|
||||
if (
|
||||
(
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::ORDERED_LIST_PARSER) != 0
|
||||
) &&
|
||||
maddy::OrderedListParser::IsStartingLine(line)
|
||||
)
|
||||
if ((!this->config || (this->config->enabledParsers &
|
||||
maddy::types::ORDERED_LIST_PARSER) != 0) &&
|
||||
maddy::OrderedListParser::IsStartingLine(line))
|
||||
{
|
||||
parser = this->createOrderedListParser();
|
||||
}
|
||||
else if (
|
||||
(
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::UNORDERED_LIST_PARSER) != 0
|
||||
) &&
|
||||
maddy::UnorderedListParser::IsStartingLine(line)
|
||||
)
|
||||
else if ((!this->config || (this->config->enabledParsers &
|
||||
maddy::types::UNORDERED_LIST_PARSER) != 0
|
||||
) &&
|
||||
maddy::UnorderedListParser::IsStartingLine(line))
|
||||
{
|
||||
parser = this->createUnorderedListParser();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user