mirror of
https://github.com/progsource/maddy.git
synced 2026-03-24 23:40: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:
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
|||||||
Copyright 2017, 2018, 2019, 2020 M. Petra Baranski
|
Copyright 2017, 2018, 2019, 2020, 2023 M. Petra Baranski
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
|||||||
10
README.md
10
README.md
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
[](https://opensource.org/licenses/MIT)
|
[](https://opensource.org/licenses/MIT)
|
||||||
[](https://semver.org/)
|
[](https://semver.org/)
|
||||||
[](https://travis-ci.org/progsource/maddy)
|
|
||||||
[](https://ci.appveyor.com/project/progsource/maddy/branch/master)
|
|
||||||
|
|
||||||
maddy is a C++ Markdown to HTML **header-only** parser library.
|
maddy is a C++ Markdown to HTML **header-only** parser library.
|
||||||
|
|
||||||
@@ -45,13 +43,17 @@ std::stringstream markdownInput("");
|
|||||||
|
|
||||||
// config is optional
|
// config is optional
|
||||||
std::shared_ptr<maddy::ParserConfig> config = std::make_shared<maddy::ParserConfig>();
|
std::shared_ptr<maddy::ParserConfig> config = std::make_shared<maddy::ParserConfig>();
|
||||||
config->isEmphasizedParserEnabled = true; // default
|
// config->isEmphasizedParserEnabled = false; // default true - this flag is deprecated
|
||||||
config->isHTMLWrappedInParagraph = true; // default
|
// config->isHTMLWrappedInParagraph = false; // default true - this flag is deprecated
|
||||||
|
config->enabledParsers &= ~maddy::types::EMPHASIZED_PARSER;
|
||||||
|
config->enabledParsers |= maddy::types::HTML_PARSER;
|
||||||
|
|
||||||
std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>(config);
|
std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>(config);
|
||||||
std::string htmlOutput = parser->Parse(markdownInput);
|
std::string htmlOutput = parser->Parse(markdownInput);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can find all parser flags in [`include/maddy/parserconfig.h`](include/maddy/parserconfig.h).
|
||||||
|
|
||||||
## How to run the tests
|
## How to run the tests
|
||||||
|
|
||||||
*(tested on Linux with
|
*(tested on Linux with
|
||||||
|
|||||||
@@ -34,11 +34,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
ParagraphParser(
|
ParagraphParser(
|
||||||
std::function<void(std::string&)> parseLineCallback,
|
std::function<void(std::string&)> parseLineCallback,
|
||||||
std::function<std::shared_ptr<BlockParser>(const std::string& line)> getBlockParserForLineCallback
|
std::function<std::shared_ptr<BlockParser>(const std::string& line)> getBlockParserForLineCallback,
|
||||||
|
bool isEnabled
|
||||||
)
|
)
|
||||||
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
||||||
, isStarted(false)
|
, isStarted(false)
|
||||||
, isFinished(false)
|
, isFinished(false)
|
||||||
|
, isEnabled(isEnabled)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,19 +90,31 @@ protected:
|
|||||||
void
|
void
|
||||||
parseBlock(std::string& line) override
|
parseBlock(std::string& line) override
|
||||||
{
|
{
|
||||||
if (!this->isStarted)
|
if (this->isEnabled && !this->isStarted)
|
||||||
{
|
{
|
||||||
line = "<p>" + line + " ";
|
line = "<p>" + line + " ";
|
||||||
this->isStarted = true;
|
this->isStarted = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if (!this->isEnabled && !this->isStarted)
|
||||||
|
{
|
||||||
|
line += " ";
|
||||||
|
this->isStarted = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (line.empty())
|
if (this->isEnabled && line.empty())
|
||||||
{
|
{
|
||||||
line += "</p>";
|
line += "</p>";
|
||||||
this->isFinished = true;
|
this->isFinished = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if (!this->isEnabled && line.empty())
|
||||||
|
{
|
||||||
|
line += "<br/>";
|
||||||
|
this->isFinished = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
line += " ";
|
line += " ";
|
||||||
}
|
}
|
||||||
@@ -108,6 +122,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
bool isStarted;
|
bool isStarted;
|
||||||
bool isFinished;
|
bool isFinished;
|
||||||
|
bool isEnabled;
|
||||||
}; // class ParagraphParser
|
}; // class ParagraphParser
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -59,15 +59,82 @@ public:
|
|||||||
*/
|
*/
|
||||||
Parser(std::shared_ptr<ParserConfig> config = nullptr)
|
Parser(std::shared_ptr<ParserConfig> config = nullptr)
|
||||||
: config(config)
|
: config(config)
|
||||||
, breakLineParser(std::make_shared<BreakLineParser>())
|
{
|
||||||
, emphasizedParser(std::make_shared<EmphasizedParser>())
|
// deprecated backward compatibility
|
||||||
, imageParser(std::make_shared<ImageParser>())
|
// will be removed in 1.4.0 latest including the booleans
|
||||||
, inlineCodeParser(std::make_shared<InlineCodeParser>())
|
if (this->config && !this->config->isEmphasizedParserEnabled)
|
||||||
, italicParser(std::make_shared<ItalicParser>())
|
{
|
||||||
, linkParser(std::make_shared<LinkParser>())
|
this->config->enabledParsers &= ~maddy::types::EMPHASIZED_PARSER;
|
||||||
, strikeThroughParser(std::make_shared<StrikeThroughParser>())
|
}
|
||||||
, strongParser(std::make_shared<StrongParser>())
|
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
|
* Parse
|
||||||
@@ -132,24 +199,46 @@ private:
|
|||||||
runLineParser(std::string& line) const
|
runLineParser(std::string& line) const
|
||||||
{
|
{
|
||||||
// Attention! ImageParser has to be before LinkParser
|
// Attention! ImageParser has to be before LinkParser
|
||||||
this->imageParser->Parse(line);
|
if (this->imageParser)
|
||||||
this->linkParser->Parse(line);
|
{
|
||||||
|
this->imageParser->Parse(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->linkParser)
|
||||||
|
{
|
||||||
|
this->linkParser->Parse(line);
|
||||||
|
}
|
||||||
|
|
||||||
// Attention! StrongParser has to be before EmphasizedParser
|
// 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->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>
|
std::shared_ptr<BlockParser>
|
||||||
@@ -157,66 +246,117 @@ private:
|
|||||||
{
|
{
|
||||||
std::shared_ptr<BlockParser> parser;
|
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>(
|
parser = std::make_shared<maddy::CodeBlockParser>(
|
||||||
nullptr,
|
nullptr,
|
||||||
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>(
|
parser = std::make_shared<maddy::HeadlineParser>(
|
||||||
nullptr,
|
nullptr,
|
||||||
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>(
|
parser = std::make_shared<maddy::HorizontalLineParser>(
|
||||||
nullptr,
|
nullptr,
|
||||||
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>(
|
parser = std::make_shared<maddy::QuoteParser>(
|
||||||
[this](std::string& line){ this->runLineParser(line); },
|
[this](std::string& line){ this->runLineParser(line); },
|
||||||
[this](const std::string& line){ return this->getBlockParserForLine(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>(
|
parser = std::make_shared<maddy::TableParser>(
|
||||||
[this](std::string& line){ this->runLineParser(line); },
|
[this](std::string& line){ this->runLineParser(line); },
|
||||||
nullptr
|
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();
|
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();
|
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();
|
parser = this->createUnorderedListParser();
|
||||||
}
|
}
|
||||||
else if (
|
else if (
|
||||||
this->config &&
|
this->config &&
|
||||||
!this->config->isHTMLWrappedInParagraph &&
|
(this->config->enabledParsers & maddy::types::HTML_PARSER) != 0 &&
|
||||||
maddy::HtmlParser::IsStartingLine(line)
|
maddy::HtmlParser::IsStartingLine(line)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
parser = std::make_shared<maddy::HtmlParser>(nullptr, nullptr);
|
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>(
|
parser = std::make_shared<maddy::ParagraphParser>(
|
||||||
[this](std::string& line){ this->runLineParser(line); },
|
[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;
|
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();
|
parser = this->createChecklistParser();
|
||||||
}
|
}
|
||||||
@@ -251,11 +397,23 @@ private:
|
|||||||
{
|
{
|
||||||
std::shared_ptr<BlockParser> parser;
|
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();
|
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();
|
parser = this->createUnorderedListParser();
|
||||||
}
|
}
|
||||||
@@ -274,11 +432,23 @@ private:
|
|||||||
{
|
{
|
||||||
std::shared_ptr<BlockParser> parser;
|
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();
|
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();
|
parser = this->createUnorderedListParser();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,50 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace maddy {
|
namespace maddy {
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace types {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PARSER_TYPE
|
||||||
|
*
|
||||||
|
* Bitwise flags to turn on/off each parser
|
||||||
|
*/
|
||||||
|
enum PARSER_TYPE : uint32_t
|
||||||
|
{
|
||||||
|
NONE = 0,
|
||||||
|
|
||||||
|
BREAKLINE_PARSER = 0b1,
|
||||||
|
CHECKLIST_PARSER = 0b10,
|
||||||
|
CODE_BLOCK_PARSER = 0b100,
|
||||||
|
EMPHASIZED_PARSER = 0b1000,
|
||||||
|
HEADLINE_PARSER = 0b10000,
|
||||||
|
HORIZONTAL_LINE_PARSER = 0b100000,
|
||||||
|
HTML_PARSER = 0b1000000,
|
||||||
|
IMAGE_PARSER = 0b10000000,
|
||||||
|
INLINE_CODE_PARSER = 0b100000000,
|
||||||
|
ITALIC_PARSER = 0b1000000000,
|
||||||
|
LINK_PARSER = 0b10000000000,
|
||||||
|
ORDERED_LIST_PARSER = 0b100000000000,
|
||||||
|
PARAGRAPH_PARSER = 0b1000000000000,
|
||||||
|
QUOTE_PARSER = 0b10000000000000,
|
||||||
|
STRIKETHROUGH_PARSER = 0b100000000000000,
|
||||||
|
STRONG_PARSER = 0b1000000000000000,
|
||||||
|
TABLE_PARSER = 0b10000000000000000,
|
||||||
|
UNORDERED_LIST_PARSER = 0b100000000000000000,
|
||||||
|
|
||||||
|
DEFAULT = 0b111111111110111111,
|
||||||
|
ALL = 0b111111111111111111,
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace types
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ParserConfig
|
* ParserConfig
|
||||||
*
|
*
|
||||||
@@ -17,12 +55,22 @@ namespace maddy {
|
|||||||
*/
|
*/
|
||||||
struct ParserConfig
|
struct ParserConfig
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @deprecated will be removed in 1.4.0 latest
|
||||||
|
*/
|
||||||
bool isEmphasizedParserEnabled;
|
bool isEmphasizedParserEnabled;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated will be removed in 1.4.0 latest
|
||||||
|
*/
|
||||||
bool isHTMLWrappedInParagraph;
|
bool isHTMLWrappedInParagraph;
|
||||||
|
|
||||||
|
uint32_t enabledParsers;
|
||||||
|
|
||||||
ParserConfig()
|
ParserConfig()
|
||||||
: isEmphasizedParserEnabled(true)
|
: isEmphasizedParserEnabled(true)
|
||||||
, isHTMLWrappedInParagraph(true)
|
, isHTMLWrappedInParagraph(true)
|
||||||
|
, enabledParsers(maddy::types::DEFAULT)
|
||||||
{}
|
{}
|
||||||
}; // class ParserConfig
|
}; // class ParserConfig
|
||||||
|
|
||||||
|
|||||||
@@ -25,4 +25,4 @@ target_include_directories(MaddyTests PUBLIC
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
)
|
)
|
||||||
target_link_libraries(MaddyTests maddy gmock_main)
|
target_link_libraries(MaddyTests maddy gmock_main)
|
||||||
add_test(MaddyTests MaddyTests)
|
add_test(NAME MaddyTests COMMAND MaddyTests)
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ protected:
|
|||||||
{
|
{
|
||||||
this->pParser = std::make_shared<maddy::ParagraphParser>(
|
this->pParser = std::make_shared<maddy::ParagraphParser>(
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr
|
nullptr,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -34,3 +34,33 @@ TEST(MADDY_PARSER, ItShouldParseWithConfig)
|
|||||||
|
|
||||||
ASSERT_EQ(testHtml2, output);
|
ASSERT_EQ(testHtml2, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(MADDY_PARSER, ItShouldParseWithBitwiseConfig)
|
||||||
|
{
|
||||||
|
auto config = std::make_shared<maddy::ParserConfig>();
|
||||||
|
config->enabledParsers &= ~maddy::types::EMPHASIZED_PARSER;
|
||||||
|
config->enabledParsers |= maddy::types::HTML_PARSER;
|
||||||
|
|
||||||
|
auto parser = std::make_shared<maddy::Parser>(config);
|
||||||
|
|
||||||
|
std::stringstream markdown(testMarkdown);
|
||||||
|
|
||||||
|
const std::string output = parser->Parse(markdown);
|
||||||
|
|
||||||
|
ASSERT_EQ(testHtml2, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(MADDY_PARSER, ItShouldParseWithSmallConfig)
|
||||||
|
{
|
||||||
|
auto config = std::make_shared<maddy::ParserConfig>();
|
||||||
|
config->enabledParsers = maddy::types::EMPHASIZED_PARSER |
|
||||||
|
maddy::types::STRONG_PARSER;
|
||||||
|
|
||||||
|
auto parser = std::make_shared<maddy::Parser>(config);
|
||||||
|
|
||||||
|
std::stringstream markdown(testMarkdown);
|
||||||
|
|
||||||
|
const std::string output = parser->Parse(markdown);
|
||||||
|
|
||||||
|
ASSERT_EQ(testHtml3, output);
|
||||||
|
}
|
||||||
|
|||||||
@@ -71,3 +71,4 @@ foot a|foot b|foot c\n\
|
|||||||
|
|
||||||
const std::string testHtml = "<h1>This is a test</h1><p>This should result in a praragraph it's that simple. </p><ul><li>an <i>unordered</i> list<ul><li>with some <strong>hierarchy</strong><ol><li>and an <em>ordered</em></li><li>list</li><li>directly</li></ol></li><li>inside</li></ul></li></ul><pre><code>\nvar c = 'blub';\n</code></pre><blockquote><p>A Quote </p><p>With some <s>text</s> blocks inside </p><ul><li>even a list </li><li>should be </li><li>possible </li></ul></blockquote><p>And well <code>inline code</code> should also work. </p><h2>Another Headline</h2><p>And not to forget <a href=\"http://progsource.de\">link to progsource</a> should work. And well - let's see how an image would be shown: </p><p><img src=\"http://progsource.de/img/progsource.png\" alt=\"an image\"/> </p><hr/><p><a name=\"to top\"></a> </p><h3>and more headlines</h3><ul class=\"checklist\"><li><label><input type=\"checkbox\"/> how</label></li><li><label><input type=\"checkbox\"/> about<ul class=\"checklist\"><li><label><input type=\"checkbox\"/> a</label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> nice</label></li></ul></label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> check</label></li><li><label><input type=\"checkbox\"/> list</label></li></ul><h4>even a table</h4><table><thead><tr><th>Left header</th><th>middle header</th><th>last header</th></tr></thead><tbody><tr><td>cell 1</td><td>cell <strong>2</strong></td><td>cell 3</td></tr><tr><td>cell 4</td><td>cell 5</td><td>cell 6</td></tr></tbody><tfoot><tr><td>foot a</td><td>foot b</td><td>foot c</td></tr></tfoot></table><h5>h5</h5><h6>h6</h6>";
|
const std::string testHtml = "<h1>This is a test</h1><p>This should result in a praragraph it's that simple. </p><ul><li>an <i>unordered</i> list<ul><li>with some <strong>hierarchy</strong><ol><li>and an <em>ordered</em></li><li>list</li><li>directly</li></ol></li><li>inside</li></ul></li></ul><pre><code>\nvar c = 'blub';\n</code></pre><blockquote><p>A Quote </p><p>With some <s>text</s> blocks inside </p><ul><li>even a list </li><li>should be </li><li>possible </li></ul></blockquote><p>And well <code>inline code</code> should also work. </p><h2>Another Headline</h2><p>And not to forget <a href=\"http://progsource.de\">link to progsource</a> should work. And well - let's see how an image would be shown: </p><p><img src=\"http://progsource.de/img/progsource.png\" alt=\"an image\"/> </p><hr/><p><a name=\"to top\"></a> </p><h3>and more headlines</h3><ul class=\"checklist\"><li><label><input type=\"checkbox\"/> how</label></li><li><label><input type=\"checkbox\"/> about<ul class=\"checklist\"><li><label><input type=\"checkbox\"/> a</label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> nice</label></li></ul></label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> check</label></li><li><label><input type=\"checkbox\"/> list</label></li></ul><h4>even a table</h4><table><thead><tr><th>Left header</th><th>middle header</th><th>last header</th></tr></thead><tbody><tr><td>cell 1</td><td>cell <strong>2</strong></td><td>cell 3</td></tr><tr><td>cell 4</td><td>cell 5</td><td>cell 6</td></tr></tbody><tfoot><tr><td>foot a</td><td>foot b</td><td>foot c</td></tr></tfoot></table><h5>h5</h5><h6>h6</h6>";
|
||||||
const std::string testHtml2 = "<h1>This is a test</h1><p>This should result in a praragraph it's that simple. </p><ul><li>an <i>unordered</i> list<ul><li>with some <strong>hierarchy</strong><ol><li>and an _ordered_</li><li>list</li><li>directly</li></ol></li><li>inside</li></ul></li></ul><pre><code>\nvar c = 'blub';\n</code></pre><blockquote><p>A Quote </p><p>With some <s>text</s> blocks inside </p><ul><li>even a list </li><li>should be </li><li>possible </li></ul></blockquote><p>And well <code>inline code</code> should also work. </p><h2>Another Headline</h2><p>And not to forget <a href=\"http://progsource.de\">link to progsource</a> should work. And well - let's see how an image would be shown: </p><p><img src=\"http://progsource.de/img/progsource.png\" alt=\"an image\"/> </p><hr/><a name=\"to top\"></a><h3>and more headlines</h3><ul class=\"checklist\"><li><label><input type=\"checkbox\"/> how</label></li><li><label><input type=\"checkbox\"/> about<ul class=\"checklist\"><li><label><input type=\"checkbox\"/> a</label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> nice</label></li></ul></label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> check</label></li><li><label><input type=\"checkbox\"/> list</label></li></ul><h4>even a table</h4><table><thead><tr><th>Left header</th><th>middle header</th><th>last header</th></tr></thead><tbody><tr><td>cell 1</td><td>cell <strong>2</strong></td><td>cell 3</td></tr><tr><td>cell 4</td><td>cell 5</td><td>cell 6</td></tr></tbody><tfoot><tr><td>foot a</td><td>foot b</td><td>foot c</td></tr></tfoot></table><h5>h5</h5><h6>h6</h6>";
|
const std::string testHtml2 = "<h1>This is a test</h1><p>This should result in a praragraph it's that simple. </p><ul><li>an <i>unordered</i> list<ul><li>with some <strong>hierarchy</strong><ol><li>and an _ordered_</li><li>list</li><li>directly</li></ol></li><li>inside</li></ul></li></ul><pre><code>\nvar c = 'blub';\n</code></pre><blockquote><p>A Quote </p><p>With some <s>text</s> blocks inside </p><ul><li>even a list </li><li>should be </li><li>possible </li></ul></blockquote><p>And well <code>inline code</code> should also work. </p><h2>Another Headline</h2><p>And not to forget <a href=\"http://progsource.de\">link to progsource</a> should work. And well - let's see how an image would be shown: </p><p><img src=\"http://progsource.de/img/progsource.png\" alt=\"an image\"/> </p><hr/><a name=\"to top\"></a><h3>and more headlines</h3><ul class=\"checklist\"><li><label><input type=\"checkbox\"/> how</label></li><li><label><input type=\"checkbox\"/> about<ul class=\"checklist\"><li><label><input type=\"checkbox\"/> a</label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> nice</label></li></ul></label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> check</label></li><li><label><input type=\"checkbox\"/> list</label></li></ul><h4>even a table</h4><table><thead><tr><th>Left header</th><th>middle header</th><th>last header</th></tr></thead><tbody><tr><td>cell 1</td><td>cell <strong>2</strong></td><td>cell 3</td></tr><tr><td>cell 4</td><td>cell 5</td><td>cell 6</td></tr></tbody><tfoot><tr><td>foot a</td><td>foot b</td><td>foot c</td></tr></tfoot></table><h5>h5</h5><h6>h6</h6>";
|
||||||
|
const std::string testHtml3 = "# This is a test <br/>This should result in a praragraph it's that simple. <br/>* an *unordered* list * with some <strong>hierarchy</strong> 1. and an <em>ordered</em> * list * directly * inside <br/>``` var c = 'blub'; ``` <br/>> A Quote > > With some ~~text~~ blocks inside > > * even a list > * should be > * possible > <br/>And well `inline code` should also work. <br/>## Another Headline <br/>And not to forget [link to progsource](http://progsource.de) should work. And well - let's see how an image would be shown: <br/> <br/>--- <br/><a name=\"to top\"></a> <br/>### and more headlines <br/>- [ ] how - [ ] about - [ ] a - [x] nice - [x] check - [ ] list <br/>#### even a table <br/>|table> Left header|middle header|last header - | - | - cell 1|cell <strong>2</strong>|cell 3 cell 4|cell 5|cell 6 - | - | - foot a|foot b|foot c |<table <br/>##### h5 ###### h6 <br/>";
|
||||||
|
|||||||
Reference in New Issue
Block a user