mirror of
https://github.com/progsource/maddy.git
synced 2026-03-25 07:50:39 +01:00
feat: add config options to en-/disable each parser
Also fix cmake line, so that ctest can find the test executable; update readme.
This commit is contained in:
@@ -59,15 +59,82 @@ public:
|
||||
*/
|
||||
Parser(std::shared_ptr<ParserConfig> config = nullptr)
|
||||
: config(config)
|
||||
, breakLineParser(std::make_shared<BreakLineParser>())
|
||||
, emphasizedParser(std::make_shared<EmphasizedParser>())
|
||||
, imageParser(std::make_shared<ImageParser>())
|
||||
, inlineCodeParser(std::make_shared<InlineCodeParser>())
|
||||
, italicParser(std::make_shared<ItalicParser>())
|
||||
, linkParser(std::make_shared<LinkParser>())
|
||||
, strikeThroughParser(std::make_shared<StrikeThroughParser>())
|
||||
, strongParser(std::make_shared<StrongParser>())
|
||||
{}
|
||||
{
|
||||
// deprecated backward compatibility
|
||||
// will be removed in 1.4.0 latest including the booleans
|
||||
if (this->config && !this->config->isEmphasizedParserEnabled)
|
||||
{
|
||||
this->config->enabledParsers &= ~maddy::types::EMPHASIZED_PARSER;
|
||||
}
|
||||
if (this->config && !this->config->isHTMLWrappedInParagraph)
|
||||
{
|
||||
this->config->enabledParsers |= maddy::types::HTML_PARSER;
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
{
|
||||
this->emphasizedParser = std::make_shared<EmphasizedParser>();
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
{
|
||||
this->inlineCodeParser = std::make_shared<InlineCodeParser>();
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
{
|
||||
this->linkParser = std::make_shared<LinkParser>();
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
{
|
||||
this->strongParser = std::make_shared<StrongParser>();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse
|
||||
@@ -132,24 +199,46 @@ private:
|
||||
runLineParser(std::string& line) const
|
||||
{
|
||||
// Attention! ImageParser has to be before LinkParser
|
||||
this->imageParser->Parse(line);
|
||||
this->linkParser->Parse(line);
|
||||
if (this->imageParser)
|
||||
{
|
||||
this->imageParser->Parse(line);
|
||||
}
|
||||
|
||||
if (this->linkParser)
|
||||
{
|
||||
this->linkParser->Parse(line);
|
||||
}
|
||||
|
||||
// Attention! StrongParser has to be before EmphasizedParser
|
||||
this->strongParser->Parse(line);
|
||||
if (this->strongParser)
|
||||
{
|
||||
this->strongParser->Parse(line);
|
||||
}
|
||||
|
||||
if (!this->config || this->config->isEmphasizedParserEnabled)
|
||||
if (this->emphasizedParser)
|
||||
{
|
||||
this->emphasizedParser->Parse(line);
|
||||
}
|
||||
|
||||
this->strikeThroughParser->Parse(line);
|
||||
if (this->strikeThroughParser)
|
||||
{
|
||||
this->strikeThroughParser->Parse(line);
|
||||
}
|
||||
|
||||
this->inlineCodeParser->Parse(line);
|
||||
if (this->inlineCodeParser)
|
||||
{
|
||||
this->inlineCodeParser->Parse(line);
|
||||
}
|
||||
|
||||
this->italicParser->Parse(line);
|
||||
if (this->italicParser)
|
||||
{
|
||||
this->italicParser->Parse(line);
|
||||
}
|
||||
|
||||
this->breakLineParser->Parse(line);
|
||||
if (this->breakLineParser)
|
||||
{
|
||||
this->breakLineParser->Parse(line);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<BlockParser>
|
||||
@@ -157,66 +246,117 @@ private:
|
||||
{
|
||||
std::shared_ptr<BlockParser> parser;
|
||||
|
||||
if (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
|
||||
);
|
||||
}
|
||||
else if (maddy::HeadlineParser::IsStartingLine(line))
|
||||
else if (
|
||||
(
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::HEADLINE_PARSER) != 0
|
||||
) &&
|
||||
maddy::HeadlineParser::IsStartingLine(line)
|
||||
)
|
||||
{
|
||||
parser = std::make_shared<maddy::HeadlineParser>(
|
||||
nullptr,
|
||||
nullptr
|
||||
);
|
||||
}
|
||||
else if (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
|
||||
);
|
||||
}
|
||||
else if (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); }
|
||||
);
|
||||
}
|
||||
else if (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
|
||||
);
|
||||
}
|
||||
else if (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 (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 (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->isHTMLWrappedInParagraph &&
|
||||
(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); },
|
||||
nullptr
|
||||
nullptr,
|
||||
(!this->config || (this->config->enabledParsers & maddy::types::PARAGRAPH_PARSER) != 0)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -232,7 +372,13 @@ private:
|
||||
{
|
||||
std::shared_ptr<BlockParser> parser;
|
||||
|
||||
if (maddy::ChecklistParser::IsStartingLine(line))
|
||||
if (
|
||||
(
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::CHECKLIST_PARSER) != 0
|
||||
) &&
|
||||
maddy::ChecklistParser::IsStartingLine(line)
|
||||
)
|
||||
{
|
||||
parser = this->createChecklistParser();
|
||||
}
|
||||
@@ -251,11 +397,23 @@ private:
|
||||
{
|
||||
std::shared_ptr<BlockParser> parser;
|
||||
|
||||
if (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 (maddy::UnorderedListParser::IsStartingLine(line))
|
||||
else if (
|
||||
(
|
||||
!this->config ||
|
||||
(this->config->enabledParsers & maddy::types::UNORDERED_LIST_PARSER) != 0
|
||||
) &&
|
||||
maddy::UnorderedListParser::IsStartingLine(line)
|
||||
)
|
||||
{
|
||||
parser = this->createUnorderedListParser();
|
||||
}
|
||||
@@ -274,11 +432,23 @@ private:
|
||||
{
|
||||
std::shared_ptr<BlockParser> parser;
|
||||
|
||||
if (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 (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