mirror of
https://github.com/progsource/maddy.git
synced 2026-03-24 23:40:39 +01:00
chore: Add clang-format
This commit is contained in:
46
.clang-format
Normal file
46
.clang-format
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
BasedOnStyle: Google
|
||||||
|
AccessModifierOffset: -2
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializers: BeforeComma
|
||||||
|
ConstructorInitializerIndentWidth: 2
|
||||||
|
BracedInitializerIndentWidth: 2
|
||||||
|
ContinuationIndentWidth: 2
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
IndentAccessModifiers: false
|
||||||
|
InsertNewlineAtEOF: true
|
||||||
|
LambdaBodyIndentation: Signature
|
||||||
|
AlignAfterOpenBracket: BlockIndent
|
||||||
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
|
BinPackArguments: false
|
||||||
|
BinPackParameters: false
|
||||||
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: true
|
||||||
|
AfterClass: true
|
||||||
|
AfterControlStatement: Always
|
||||||
|
AfterEnum: true
|
||||||
|
AfterFunction: true
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterStruct: true
|
||||||
|
AfterUnion: true
|
||||||
|
AfterExternBlock: false
|
||||||
|
BeforeCatch: true
|
||||||
|
BeforeElse: true
|
||||||
|
BeforeLambdaBody: true
|
||||||
|
IndentBraces: false
|
||||||
|
BeforeWhile: true
|
||||||
|
SplitEmptyFunction: false
|
||||||
|
SplitEmptyRecord: false
|
||||||
|
SplitEmptyNamespace: false
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '^<.*>'
|
||||||
|
Priority: 1
|
||||||
|
- Regex: '^"maddy/.*'
|
||||||
|
Priority: 3
|
||||||
|
- Regex: '.*'
|
||||||
|
Priority: 2
|
||||||
|
SortIncludes: true
|
||||||
|
IncludeBlocks: Regroup
|
||||||
|
InsertTrailingCommas: Wrapped
|
||||||
@@ -8,5 +8,8 @@ indent_style = space
|
|||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
[*.{h,hh,hpp,c,cc,cpp,cxx,yml}]
|
[*.{h,hh,hpp,c,cc,cpp,cxx,yml,py,md}]
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[CMakeLists.txt]
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
|||||||
25
.github/workflows/run-checks.yml
vendored
Normal file
25
.github/workflows/run-checks.yml
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
name: run-checks
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
run-clang-format:
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.8'
|
||||||
|
|
||||||
|
- name: Run format script with dry_run
|
||||||
|
run: |
|
||||||
|
clang-format --version
|
||||||
|
python tools/format.py dry_run
|
||||||
@@ -15,6 +15,7 @@ maddy uses [semver versioning](https://semver.org/).
|
|||||||
## Upcoming
|
## Upcoming
|
||||||
|
|
||||||
*  Updated google test to v1.15.0.
|
*  Updated google test to v1.15.0.
|
||||||
|
*  clang-format
|
||||||
|
|
||||||
## version 1.3.0 2023-08-26
|
## version 1.3.0 2023-08-26
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
// windows compatibility includes
|
// windows compatibility includes
|
||||||
#include <cctype>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cctype>
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -36,11 +36,13 @@ public:
|
|||||||
*
|
*
|
||||||
* @method
|
* @method
|
||||||
* @param {std::function<void(std::string&)>} parseLineCallback
|
* @param {std::function<void(std::string&)>} parseLineCallback
|
||||||
* @param {std::function<std::shared_ptr<BlockParser>(const std::string& line)>} getBlockParserForLineCallback
|
* @param {std::function<std::shared_ptr<BlockParser>(const std::string&
|
||||||
|
* line)>} getBlockParserForLineCallback
|
||||||
*/
|
*/
|
||||||
BlockParser(
|
BlockParser(
|
||||||
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
|
||||||
)
|
)
|
||||||
: result("", std::ios_base::ate | std::ios_base::in | std::ios_base::out)
|
: result("", std::ios_base::ate | std::ios_base::in | std::ios_base::out)
|
||||||
, childParser(nullptr)
|
, childParser(nullptr)
|
||||||
@@ -64,8 +66,7 @@ public:
|
|||||||
* @param {std::string&} line
|
* @param {std::string&} line
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
virtual void
|
virtual void AddLine(std::string& line)
|
||||||
AddLine(std::string& line)
|
|
||||||
{
|
{
|
||||||
this->parseBlock(line);
|
this->parseBlock(line);
|
||||||
|
|
||||||
@@ -113,11 +114,7 @@ public:
|
|||||||
* @method
|
* @method
|
||||||
* @return {std::stringstream}
|
* @return {std::stringstream}
|
||||||
*/
|
*/
|
||||||
std::stringstream&
|
std::stringstream& GetResult() { return this->result; }
|
||||||
GetResult()
|
|
||||||
{
|
|
||||||
return this->result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear
|
* Clear
|
||||||
@@ -129,11 +126,7 @@ public:
|
|||||||
* @method
|
* @method
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
void
|
void Clear() { this->result.str(""); }
|
||||||
Clear()
|
|
||||||
{
|
|
||||||
this->result.str("");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::stringstream result;
|
std::stringstream result;
|
||||||
@@ -143,8 +136,7 @@ protected:
|
|||||||
virtual bool isLineParserAllowed() const = 0;
|
virtual bool isLineParserAllowed() const = 0;
|
||||||
virtual void parseBlock(std::string& line) = 0;
|
virtual void parseBlock(std::string& line) = 0;
|
||||||
|
|
||||||
void
|
void parseLine(std::string& line)
|
||||||
parseLine(std::string& line)
|
|
||||||
{
|
{
|
||||||
if (parseLineCallback)
|
if (parseLineCallback)
|
||||||
{
|
{
|
||||||
@@ -152,13 +144,11 @@ protected:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t
|
uint32_t getIndentationWidth(const std::string& line) const
|
||||||
getIndentationWidth(const std::string& line) const
|
|
||||||
{
|
{
|
||||||
bool hasMetNonSpace = false;
|
bool hasMetNonSpace = false;
|
||||||
|
|
||||||
uint32_t indentation = static_cast<uint32_t>(
|
uint32_t indentation = static_cast<uint32_t>(std::count_if(
|
||||||
std::count_if(
|
|
||||||
line.begin(),
|
line.begin(),
|
||||||
line.end(),
|
line.end(),
|
||||||
[&hasMetNonSpace](unsigned char c)
|
[&hasMetNonSpace](unsigned char c)
|
||||||
@@ -176,14 +166,12 @@ protected:
|
|||||||
hasMetNonSpace = true;
|
hasMetNonSpace = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
return indentation;
|
return indentation;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<BlockParser>
|
std::shared_ptr<BlockParser> getBlockParserForLine(const std::string& line)
|
||||||
getBlockParserForLine(const std::string& line)
|
|
||||||
{
|
{
|
||||||
if (getBlockParserForLineCallback)
|
if (getBlockParserForLineCallback)
|
||||||
{
|
{
|
||||||
@@ -195,7 +183,8 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
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;
|
||||||
}; // class BlockParser
|
}; // class BlockParser
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "maddy/lineparser.h"
|
#include "maddy/lineparser.h"
|
||||||
|
|
||||||
@@ -36,8 +36,7 @@ public:
|
|||||||
* @param {std::string&} line The line to interpret
|
* @param {std::string&} line The line to interpret
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
void
|
void Parse(std::string& line) override
|
||||||
Parse(std::string& line) override
|
|
||||||
{
|
{
|
||||||
static std::regex re(R"((\r\n|\r))");
|
static std::regex re(R"((\r\n|\r))");
|
||||||
static std::string replacement = "<br>";
|
static std::string replacement = "<br>";
|
||||||
|
|||||||
@@ -31,11 +31,13 @@ public:
|
|||||||
*
|
*
|
||||||
* @method
|
* @method
|
||||||
* @param {std::function<void(std::string&)>} parseLineCallback
|
* @param {std::function<void(std::string&)>} parseLineCallback
|
||||||
* @param {std::function<std::shared_ptr<BlockParser>(const std::string& line)>} getBlockParserForLineCallback
|
* @param {std::function<std::shared_ptr<BlockParser>(const std::string&
|
||||||
|
* line)>} getBlockParserForLineCallback
|
||||||
*/
|
*/
|
||||||
ChecklistParser(
|
ChecklistParser(
|
||||||
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
|
||||||
)
|
)
|
||||||
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
||||||
, isStarted(false)
|
, isStarted(false)
|
||||||
@@ -51,8 +53,7 @@ public:
|
|||||||
* @param {const std::string&} line
|
* @param {const std::string&} line
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool IsStartingLine(const std::string& line)
|
||||||
IsStartingLine(const std::string& line)
|
|
||||||
{
|
{
|
||||||
static std::regex re(R"(^- \[[x| ]\] .*)");
|
static std::regex re(R"(^- \[[x| ]\] .*)");
|
||||||
return std::regex_match(line, re);
|
return std::regex_match(line, re);
|
||||||
@@ -64,27 +65,14 @@ public:
|
|||||||
* @method
|
* @method
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
bool
|
bool IsFinished() const override { return this->isFinished; }
|
||||||
IsFinished() const override
|
|
||||||
{
|
|
||||||
return this->isFinished;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool
|
bool isInlineBlockAllowed() const override { return true; }
|
||||||
isInlineBlockAllowed() const override
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool isLineParserAllowed() const override { return true; }
|
||||||
isLineParserAllowed() const override
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void parseBlock(std::string& line) override
|
||||||
parseBlock(std::string& line) override
|
|
||||||
{
|
{
|
||||||
bool isStartOfNewListItem = IsStartingLine(line);
|
bool isStartOfNewListItem = IsStartingLine(line);
|
||||||
uint32_t indentation = getIndentationWidth(line);
|
uint32_t indentation = getIndentationWidth(line);
|
||||||
@@ -97,7 +85,8 @@ protected:
|
|||||||
line = std::regex_replace(line, emptyBoxRegex, emptyBoxReplacement);
|
line = std::regex_replace(line, emptyBoxRegex, emptyBoxReplacement);
|
||||||
|
|
||||||
static std::regex boxRegex(R"(^\[x\])");
|
static std::regex boxRegex(R"(^\[x\])");
|
||||||
static std::string boxReplacement = "<input type=\"checkbox\" checked=\"checked\"/>";
|
static std::string boxReplacement =
|
||||||
|
"<input type=\"checkbox\" checked=\"checked\"/>";
|
||||||
line = std::regex_replace(line, boxRegex, boxReplacement);
|
line = std::regex_replace(line, boxRegex, boxReplacement);
|
||||||
|
|
||||||
if (!this->isStarted)
|
if (!this->isStarted)
|
||||||
@@ -113,11 +102,9 @@ protected:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (line.empty() ||
|
||||||
line.empty() ||
|
|
||||||
line.find("</label></li><li><label>") != std::string::npos ||
|
line.find("</label></li><li><label>") != std::string::npos ||
|
||||||
line.find("</label></li></ul>") != std::string::npos
|
line.find("</label></li></ul>") != std::string::npos)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
line = "</label></li></ul>" + line;
|
line = "</label></li></ul>" + line;
|
||||||
this->isFinished = true;
|
this->isFinished = true;
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string>
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "maddy/blockparser.h"
|
#include "maddy/blockparser.h"
|
||||||
|
|
||||||
@@ -47,11 +47,13 @@ public:
|
|||||||
*
|
*
|
||||||
* @method
|
* @method
|
||||||
* @param {std::function<void(std::string&)>} parseLineCallback
|
* @param {std::function<void(std::string&)>} parseLineCallback
|
||||||
* @param {std::function<std::shared_ptr<BlockParser>(const std::string& line)>} getBlockParserForLineCallback
|
* @param {std::function<std::shared_ptr<BlockParser>(const std::string&
|
||||||
|
* line)>} getBlockParserForLineCallback
|
||||||
*/
|
*/
|
||||||
CodeBlockParser(
|
CodeBlockParser(
|
||||||
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
|
||||||
)
|
)
|
||||||
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
||||||
, isStarted(false)
|
, isStarted(false)
|
||||||
@@ -71,8 +73,7 @@ public:
|
|||||||
* @param {const std::string&} line
|
* @param {const std::string&} line
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool IsStartingLine(const std::string& line)
|
||||||
IsStartingLine(const std::string& line)
|
|
||||||
{
|
{
|
||||||
static std::regex re("^(?:`){3}(.*)$");
|
static std::regex re("^(?:`){3}(.*)$");
|
||||||
return std::regex_match(line, re);
|
return std::regex_match(line, re);
|
||||||
@@ -84,27 +85,14 @@ public:
|
|||||||
* @method
|
* @method
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
bool
|
bool IsFinished() const override { return this->isFinished; }
|
||||||
IsFinished() const override
|
|
||||||
{
|
|
||||||
return this->isFinished;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool
|
bool isInlineBlockAllowed() const override { return false; }
|
||||||
isInlineBlockAllowed() const override
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool isLineParserAllowed() const override { return false; }
|
||||||
isLineParserAllowed() const override
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void parseBlock(std::string& line) override
|
||||||
parseBlock(std::string& line) override
|
|
||||||
{
|
{
|
||||||
if (line == "```")
|
if (line == "```")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "maddy/lineparser.h"
|
#include "maddy/lineparser.h"
|
||||||
|
|
||||||
@@ -38,10 +38,11 @@ public:
|
|||||||
* @param {std::string&} line The line to interpret
|
* @param {std::string&} line The line to interpret
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
void
|
void Parse(std::string& line) override
|
||||||
Parse(std::string& line) override
|
|
||||||
{
|
{
|
||||||
static std::regex re(R"((?!.*`.*|.*<code>.*)_(?!.*`.*|.*<\/code>.*)([^_]*)_(?!.*`.*|.*<\/code>.*))");
|
static std::regex re(
|
||||||
|
R"((?!.*`.*|.*<code>.*)_(?!.*`.*|.*<\/code>.*)([^_]*)_(?!.*`.*|.*<\/code>.*))"
|
||||||
|
);
|
||||||
static std::string replacement = "<em>$1</em>";
|
static std::string replacement = "<em>$1</em>";
|
||||||
|
|
||||||
line = std::regex_replace(line, re, replacement);
|
line = std::regex_replace(line, re, replacement);
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string>
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "maddy/blockparser.h"
|
#include "maddy/blockparser.h"
|
||||||
|
|
||||||
@@ -53,11 +53,13 @@ public:
|
|||||||
*
|
*
|
||||||
* @method
|
* @method
|
||||||
* @param {std::function<void(std::string&)>} parseLineCallback
|
* @param {std::function<void(std::string&)>} parseLineCallback
|
||||||
* @param {std::function<std::shared_ptr<BlockParser>(const std::string& line)>} getBlockParserForLineCallback
|
* @param {std::function<std::shared_ptr<BlockParser>(const std::string&
|
||||||
|
* line)>} getBlockParserForLineCallback
|
||||||
*/
|
*/
|
||||||
HeadlineParser(
|
HeadlineParser(
|
||||||
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 isInlineParserAllowed = true
|
bool isInlineParserAllowed = true
|
||||||
)
|
)
|
||||||
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
||||||
@@ -73,8 +75,7 @@ public:
|
|||||||
* @param {const std::string&} line
|
* @param {const std::string&} line
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool IsStartingLine(const std::string& line)
|
||||||
IsStartingLine(const std::string& line)
|
|
||||||
{
|
{
|
||||||
static std::regex re("^(?:#){1,6} (.*)");
|
static std::regex re("^(?:#){1,6} (.*)");
|
||||||
return std::regex_match(line, re);
|
return std::regex_match(line, re);
|
||||||
@@ -89,43 +90,33 @@ public:
|
|||||||
* @method
|
* @method
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
bool
|
bool IsFinished() const override { return true; }
|
||||||
IsFinished() const override
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool
|
bool isInlineBlockAllowed() const override { return false; }
|
||||||
isInlineBlockAllowed() const override
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool isLineParserAllowed() const override
|
||||||
isLineParserAllowed() const override
|
|
||||||
{
|
{
|
||||||
return this->isInlineParserAllowed;
|
return this->isInlineParserAllowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void parseBlock(std::string& line) override
|
||||||
parseBlock(std::string& line) override
|
|
||||||
{
|
{
|
||||||
static std::vector<std::regex> hlRegex = {
|
static std::vector<std::regex> hlRegex = {
|
||||||
std::regex("^# (.*)")
|
std::regex("^# (.*)"),
|
||||||
, std::regex("^(?:#){2} (.*)")
|
std::regex("^(?:#){2} (.*)"),
|
||||||
, std::regex("^(?:#){3} (.*)")
|
std::regex("^(?:#){3} (.*)"),
|
||||||
, std::regex("^(?:#){4} (.*)")
|
std::regex("^(?:#){4} (.*)"),
|
||||||
, std::regex("^(?:#){5} (.*)")
|
std::regex("^(?:#){5} (.*)"),
|
||||||
, std::regex("^(?:#){6} (.*)")
|
std::regex("^(?:#){6} (.*)")
|
||||||
};
|
};
|
||||||
static std::vector<std::string> hlReplacement = {
|
static std::vector<std::string> hlReplacement = {
|
||||||
"<h1>$1</h1>"
|
"<h1>$1</h1>",
|
||||||
, "<h2>$1</h2>"
|
"<h2>$1</h2>",
|
||||||
, "<h3>$1</h3>"
|
"<h3>$1</h3>",
|
||||||
, "<h4>$1</h4>"
|
"<h4>$1</h4>",
|
||||||
, "<h5>$1</h5>"
|
"<h5>$1</h5>",
|
||||||
, "<h6>$1</h6>"
|
"<h6>$1</h6>"
|
||||||
};
|
};
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 6; ++i)
|
for (uint8_t i = 0; i < 6; ++i)
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string>
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "maddy/blockparser.h"
|
#include "maddy/blockparser.h"
|
||||||
|
|
||||||
@@ -35,11 +35,13 @@ public:
|
|||||||
*
|
*
|
||||||
* @method
|
* @method
|
||||||
* @param {std::function<void(std::string&)>} parseLineCallback
|
* @param {std::function<void(std::string&)>} parseLineCallback
|
||||||
* @param {std::function<std::shared_ptr<BlockParser>(const std::string& line)>} getBlockParserForLineCallback
|
* @param {std::function<std::shared_ptr<BlockParser>(const std::string&
|
||||||
|
* line)>} getBlockParserForLineCallback
|
||||||
*/
|
*/
|
||||||
HorizontalLineParser(
|
HorizontalLineParser(
|
||||||
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
|
||||||
)
|
)
|
||||||
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
||||||
, lineRegex("^---$")
|
, lineRegex("^---$")
|
||||||
@@ -54,8 +56,7 @@ public:
|
|||||||
* @param {const std::string&} line
|
* @param {const std::string&} line
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool IsStartingLine(const std::string& line)
|
||||||
IsStartingLine(const std::string& line)
|
|
||||||
{
|
{
|
||||||
static std::regex re("^---$");
|
static std::regex re("^---$");
|
||||||
return std::regex_match(line, re);
|
return std::regex_match(line, re);
|
||||||
@@ -70,27 +71,14 @@ public:
|
|||||||
* @method
|
* @method
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
bool
|
bool IsFinished() const override { return true; }
|
||||||
IsFinished() const override
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool
|
bool isInlineBlockAllowed() const override { return false; }
|
||||||
isInlineBlockAllowed() const override
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool isLineParserAllowed() const override { return false; }
|
||||||
isLineParserAllowed() const override
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void parseBlock(std::string& line) override
|
||||||
parseBlock(std::string& line) override
|
|
||||||
{
|
{
|
||||||
static std::string replacement = "<hr/>";
|
static std::string replacement = "<hr/>";
|
||||||
|
|
||||||
|
|||||||
@@ -30,11 +30,13 @@ public:
|
|||||||
*
|
*
|
||||||
* @method
|
* @method
|
||||||
* @param {std::function<void(std::string&)>} parseLineCallback
|
* @param {std::function<void(std::string&)>} parseLineCallback
|
||||||
* @param {std::function<std::shared_ptr<BlockParser>(const std::string& line)>} getBlockParserForLineCallback
|
* @param {std::function<std::shared_ptr<BlockParser>(const std::string&
|
||||||
|
* line)>} getBlockParserForLineCallback
|
||||||
*/
|
*/
|
||||||
HtmlParser(
|
HtmlParser(
|
||||||
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
|
||||||
)
|
)
|
||||||
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
||||||
, isStarted(false)
|
, isStarted(false)
|
||||||
@@ -52,11 +54,7 @@ public:
|
|||||||
* @param {const std::string&} line
|
* @param {const std::string&} line
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool IsStartingLine(const std::string& line) { return line[0] == '<'; }
|
||||||
IsStartingLine(const std::string& line)
|
|
||||||
{
|
|
||||||
return line[0] == '<';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IsFinished
|
* IsFinished
|
||||||
@@ -66,27 +64,14 @@ public:
|
|||||||
* @method
|
* @method
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
bool
|
bool IsFinished() const override { return this->isFinished; }
|
||||||
IsFinished() const override
|
|
||||||
{
|
|
||||||
return this->isFinished;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool
|
bool isInlineBlockAllowed() const override { return false; }
|
||||||
isInlineBlockAllowed() const override
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool isLineParserAllowed() const override { return false; }
|
||||||
isLineParserAllowed() const override
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void parseBlock(std::string& line) override
|
||||||
parseBlock(std::string& line) override
|
|
||||||
{
|
{
|
||||||
if (!this->isStarted)
|
if (!this->isStarted)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "maddy/lineparser.h"
|
#include "maddy/lineparser.h"
|
||||||
|
|
||||||
@@ -38,8 +38,7 @@ public:
|
|||||||
* @param {std::string&} line The line to interpret
|
* @param {std::string&} line The line to interpret
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
void
|
void Parse(std::string& line) override
|
||||||
Parse(std::string& line) override
|
|
||||||
{
|
{
|
||||||
static std::regex re(R"(\!\[([^\]]*)\]\(([^\]]*)\))");
|
static std::regex re(R"(\!\[([^\]]*)\]\(([^\]]*)\))");
|
||||||
static std::string replacement = "<img src=\"$2\" alt=\"$1\"/>";
|
static std::string replacement = "<img src=\"$2\" alt=\"$1\"/>";
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "maddy/lineparser.h"
|
#include "maddy/lineparser.h"
|
||||||
|
|
||||||
@@ -36,8 +36,7 @@ public:
|
|||||||
* @param {std::string&} line The line to interpret
|
* @param {std::string&} line The line to interpret
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
void
|
void Parse(std::string& line) override
|
||||||
Parse(std::string& line) override
|
|
||||||
{
|
{
|
||||||
static std::regex re("`([^`]*)`");
|
static std::regex re("`([^`]*)`");
|
||||||
static std::string replacement = "<code>$1</code>";
|
static std::string replacement = "<code>$1</code>";
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "maddy/lineparser.h"
|
#include "maddy/lineparser.h"
|
||||||
|
|
||||||
@@ -36,10 +36,11 @@ public:
|
|||||||
* @param {std::string&} line The line to interpret
|
* @param {std::string&} line The line to interpret
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
void
|
void Parse(std::string& line) override
|
||||||
Parse(std::string& line) override
|
|
||||||
{
|
{
|
||||||
static std::regex re(R"((?!.*`.*|.*<code>.*)\*(?!.*`.*|.*<\/code>.*)([^\*]*)\*(?!.*`.*|.*<\/code>.*))");
|
static std::regex re(
|
||||||
|
R"((?!.*`.*|.*<code>.*)\*(?!.*`.*|.*<\/code>.*)([^\*]*)\*(?!.*`.*|.*<\/code>.*))"
|
||||||
|
);
|
||||||
static std::string replacement = "<i>$1</i>";
|
static std::string replacement = "<i>$1</i>";
|
||||||
line = std::regex_replace(line, re, replacement);
|
line = std::regex_replace(line, re, replacement);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string>
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "maddy/blockparser.h"
|
#include "maddy/blockparser.h"
|
||||||
|
|
||||||
@@ -51,11 +51,13 @@ public:
|
|||||||
*
|
*
|
||||||
* @method
|
* @method
|
||||||
* @param {std::function<void(std::string&)>} parseLineCallback
|
* @param {std::function<void(std::string&)>} parseLineCallback
|
||||||
* @param {std::function<std::shared_ptr<BlockParser>(const std::string& line)>} getBlockParserForLineCallback
|
* @param {std::function<std::shared_ptr<BlockParser>(const std::string&
|
||||||
|
* line)>} getBlockParserForLineCallback
|
||||||
*/
|
*/
|
||||||
LatexBlockParser(
|
LatexBlockParser(
|
||||||
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
|
||||||
)
|
)
|
||||||
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
||||||
, isStarted(false)
|
, isStarted(false)
|
||||||
@@ -75,8 +77,7 @@ public:
|
|||||||
* @param {const std::string&} line
|
* @param {const std::string&} line
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool IsStartingLine(const std::string& line)
|
||||||
IsStartingLine(const std::string& line)
|
|
||||||
{
|
{
|
||||||
static std::regex re(R"(^(?:\$){2}(.*)$)");
|
static std::regex re(R"(^(?:\$){2}(.*)$)");
|
||||||
return std::regex_match(line, re);
|
return std::regex_match(line, re);
|
||||||
@@ -88,27 +89,14 @@ public:
|
|||||||
* @method
|
* @method
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
bool
|
bool IsFinished() const override { return this->isFinished; }
|
||||||
IsFinished() const override
|
|
||||||
{
|
|
||||||
return this->isFinished;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool
|
bool isInlineBlockAllowed() const override { return false; }
|
||||||
isInlineBlockAllowed() const override
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool isLineParserAllowed() const override { return false; }
|
||||||
isLineParserAllowed() const override
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void parseBlock(std::string& line) override
|
||||||
parseBlock(std::string& line) override
|
|
||||||
{
|
{
|
||||||
if (!this->isStarted && line.substr(0, 2) == "$$")
|
if (!this->isStarted && line.substr(0, 2) == "$$")
|
||||||
{
|
{
|
||||||
@@ -116,7 +104,8 @@ protected:
|
|||||||
this->isFinished = false;
|
this->isFinished = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->isStarted && !this->isFinished && line.size() > 1 && line.substr(line.size() - 2, 2) == "$$")
|
if (this->isStarted && !this->isFinished && line.size() > 1 &&
|
||||||
|
line.substr(line.size() - 2, 2) == "$$")
|
||||||
{
|
{
|
||||||
this->isFinished = true;
|
this->isFinished = true;
|
||||||
this->isStarted = false;
|
this->isStarted = false;
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "maddy/lineparser.h"
|
#include "maddy/lineparser.h"
|
||||||
|
|
||||||
@@ -38,8 +38,7 @@ public:
|
|||||||
* @param {std::string&} line The line to interpret
|
* @param {std::string&} line The line to interpret
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
void
|
void Parse(std::string& line) override
|
||||||
Parse(std::string& line) override
|
|
||||||
{
|
{
|
||||||
static std::regex re(R"(\[([^\]]*)\]\(([^\]]*)\))");
|
static std::regex re(R"(\[([^\]]*)\]\(([^\]]*)\))");
|
||||||
static std::string replacement = "<a href=\"$2\">$1</a>";
|
static std::string replacement = "<a href=\"$2\">$1</a>";
|
||||||
|
|||||||
@@ -31,11 +31,13 @@ public:
|
|||||||
*
|
*
|
||||||
* @method
|
* @method
|
||||||
* @param {std::function<void(std::string&)>} parseLineCallback
|
* @param {std::function<void(std::string&)>} parseLineCallback
|
||||||
* @param {std::function<std::shared_ptr<BlockParser>(const std::string& line)>} getBlockParserForLineCallback
|
* @param {std::function<std::shared_ptr<BlockParser>(const std::string&
|
||||||
|
* line)>} getBlockParserForLineCallback
|
||||||
*/
|
*/
|
||||||
OrderedListParser(
|
OrderedListParser(
|
||||||
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
|
||||||
)
|
)
|
||||||
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
||||||
, isStarted(false)
|
, isStarted(false)
|
||||||
@@ -51,8 +53,7 @@ public:
|
|||||||
* @param {const std::string&} line
|
* @param {const std::string&} line
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool IsStartingLine(const std::string& line)
|
||||||
IsStartingLine(const std::string& line)
|
|
||||||
{
|
{
|
||||||
static std::regex re("^1\\. .*");
|
static std::regex re("^1\\. .*");
|
||||||
return std::regex_match(line, re);
|
return std::regex_match(line, re);
|
||||||
@@ -64,27 +65,14 @@ public:
|
|||||||
* @method
|
* @method
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
bool
|
bool IsFinished() const override { return this->isFinished; }
|
||||||
IsFinished() const override
|
|
||||||
{
|
|
||||||
return this->isFinished;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool
|
bool isInlineBlockAllowed() const override { return true; }
|
||||||
isInlineBlockAllowed() const override
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool isLineParserAllowed() const override { return true; }
|
||||||
isLineParserAllowed() const override
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void parseBlock(std::string& line) override
|
||||||
parseBlock(std::string& line) override
|
|
||||||
{
|
{
|
||||||
bool isStartOfNewListItem = this->isStartOfNewListItem(line);
|
bool isStartOfNewListItem = this->isStartOfNewListItem(line);
|
||||||
uint32_t indentation = getIndentationWidth(line);
|
uint32_t indentation = getIndentationWidth(line);
|
||||||
@@ -107,12 +95,9 @@ protected:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (line.empty() || line.find("</li><li>") != std::string::npos ||
|
||||||
line.empty() ||
|
|
||||||
line.find("</li><li>") != std::string::npos ||
|
|
||||||
line.find("</li></ol>") != std::string::npos ||
|
line.find("</li></ol>") != std::string::npos ||
|
||||||
line.find("</li></ul>") != std::string::npos
|
line.find("</li></ul>") != std::string::npos)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
line = "</li></ol>" + line;
|
line = "</li></ol>" + line;
|
||||||
this->isFinished = true;
|
this->isFinished = true;
|
||||||
@@ -129,8 +114,7 @@ private:
|
|||||||
bool isStarted;
|
bool isStarted;
|
||||||
bool isFinished;
|
bool isFinished;
|
||||||
|
|
||||||
bool
|
bool isStartOfNewListItem(const std::string& line) const
|
||||||
isStartOfNewListItem(const std::string& line) const
|
|
||||||
{
|
{
|
||||||
static std::regex re(R"(^(?:[1-9]+[0-9]*\. |\* ).*)");
|
static std::regex re(R"(^(?:[1-9]+[0-9]*\. |\* ).*)");
|
||||||
return std::regex_match(line, re);
|
return std::regex_match(line, re);
|
||||||
|
|||||||
@@ -30,11 +30,13 @@ public:
|
|||||||
*
|
*
|
||||||
* @method
|
* @method
|
||||||
* @param {std::function<void(std::string&)>} parseLineCallback
|
* @param {std::function<void(std::string&)>} parseLineCallback
|
||||||
* @param {std::function<std::shared_ptr<BlockParser>(const std::string& line)>} getBlockParserForLineCallback
|
* @param {std::function<std::shared_ptr<BlockParser>(const std::string&
|
||||||
|
* line)>} getBlockParserForLineCallback
|
||||||
*/
|
*/
|
||||||
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
|
bool isEnabled
|
||||||
)
|
)
|
||||||
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
||||||
@@ -54,11 +56,7 @@ public:
|
|||||||
* @param {const std::string&} line
|
* @param {const std::string&} line
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool IsStartingLine(const std::string& line) { return !line.empty(); }
|
||||||
IsStartingLine(const std::string& line)
|
|
||||||
{
|
|
||||||
return !line.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IsFinished
|
* IsFinished
|
||||||
@@ -68,27 +66,14 @@ public:
|
|||||||
* @method
|
* @method
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
bool
|
bool IsFinished() const override { return this->isFinished; }
|
||||||
IsFinished() const override
|
|
||||||
{
|
|
||||||
return this->isFinished;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool
|
bool isInlineBlockAllowed() const override { return false; }
|
||||||
isInlineBlockAllowed() const override
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool isLineParserAllowed() const override { return true; }
|
||||||
isLineParserAllowed() const override
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void parseBlock(std::string& line) override
|
||||||
parseBlock(std::string& line) override
|
|
||||||
{
|
{
|
||||||
if (this->isEnabled && !this->isStarted)
|
if (this->isEnabled && !this->isStarted)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "maddy/parserconfig.h"
|
#include "maddy/parserconfig.h"
|
||||||
@@ -57,7 +57,11 @@ public:
|
|||||||
* Check https://github.com/progsource/maddy/blob/master/CHANGELOG.md
|
* Check https://github.com/progsource/maddy/blob/master/CHANGELOG.md
|
||||||
* for the changelog.
|
* 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
|
* ctor
|
||||||
@@ -66,8 +70,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @method
|
* @method
|
||||||
*/
|
*/
|
||||||
Parser(std::shared_ptr<ParserConfig> config = nullptr)
|
Parser(std::shared_ptr<ParserConfig> config = nullptr) : config(config)
|
||||||
: config(config)
|
|
||||||
{
|
{
|
||||||
// deprecated backward compatibility
|
// deprecated backward compatibility
|
||||||
// will be removed in 1.4.0 latest including the booleans
|
// will be removed in 1.4.0 latest including the booleans
|
||||||
@@ -80,66 +83,50 @@ public:
|
|||||||
this->config->enabledParsers |= maddy::types::HTML_PARSER;
|
this->config->enabledParsers |= maddy::types::HTML_PARSER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!this->config ||
|
||||||
!this->config ||
|
(this->config->enabledParsers & maddy::types::BREAKLINE_PARSER) != 0)
|
||||||
(this->config->enabledParsers & maddy::types::BREAKLINE_PARSER) != 0
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
this->breakLineParser = std::make_shared<BreakLineParser>();
|
this->breakLineParser = std::make_shared<BreakLineParser>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!this->config ||
|
||||||
!this->config ||
|
(this->config->enabledParsers & maddy::types::EMPHASIZED_PARSER) != 0)
|
||||||
(this->config->enabledParsers & maddy::types::EMPHASIZED_PARSER) != 0
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
this->emphasizedParser = std::make_shared<EmphasizedParser>();
|
this->emphasizedParser = std::make_shared<EmphasizedParser>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!this->config ||
|
||||||
!this->config ||
|
(this->config->enabledParsers & maddy::types::IMAGE_PARSER) != 0)
|
||||||
(this->config->enabledParsers & maddy::types::IMAGE_PARSER) != 0
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
this->imageParser = std::make_shared<ImageParser>();
|
this->imageParser = std::make_shared<ImageParser>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!this->config ||
|
||||||
!this->config ||
|
(this->config->enabledParsers & maddy::types::INLINE_CODE_PARSER) != 0)
|
||||||
(this->config->enabledParsers & maddy::types::INLINE_CODE_PARSER) != 0
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
this->inlineCodeParser = std::make_shared<InlineCodeParser>();
|
this->inlineCodeParser = std::make_shared<InlineCodeParser>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!this->config ||
|
||||||
!this->config ||
|
(this->config->enabledParsers & maddy::types::ITALIC_PARSER) != 0)
|
||||||
(this->config->enabledParsers & maddy::types::ITALIC_PARSER) != 0
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
this->italicParser = std::make_shared<ItalicParser>();
|
this->italicParser = std::make_shared<ItalicParser>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!this->config ||
|
||||||
!this->config ||
|
(this->config->enabledParsers & maddy::types::LINK_PARSER) != 0)
|
||||||
(this->config->enabledParsers & maddy::types::LINK_PARSER) != 0
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
this->linkParser = std::make_shared<LinkParser>();
|
this->linkParser = std::make_shared<LinkParser>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!this->config || (this->config->enabledParsers &
|
||||||
!this->config ||
|
maddy::types::STRIKETHROUGH_PARSER) != 0)
|
||||||
(this->config->enabledParsers & maddy::types::STRIKETHROUGH_PARSER) != 0
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
this->strikeThroughParser = std::make_shared<StrikeThroughParser>();
|
this->strikeThroughParser = std::make_shared<StrikeThroughParser>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!this->config ||
|
||||||
!this->config ||
|
(this->config->enabledParsers & maddy::types::STRONG_PARSER) != 0)
|
||||||
(this->config->enabledParsers & maddy::types::STRONG_PARSER) != 0
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
this->strongParser = std::make_shared<StrongParser>();
|
this->strongParser = std::make_shared<StrongParser>();
|
||||||
}
|
}
|
||||||
@@ -152,8 +139,7 @@ public:
|
|||||||
* @param {const std::istream&} markdown
|
* @param {const std::istream&} markdown
|
||||||
* @return {std::string} HTML
|
* @return {std::string} HTML
|
||||||
*/
|
*/
|
||||||
std::string
|
std::string Parse(std::istream& markdown) const
|
||||||
Parse(std::istream& markdown) const
|
|
||||||
{
|
{
|
||||||
std::string result = "";
|
std::string result = "";
|
||||||
std::shared_ptr<BlockParser> currentBlockParser = nullptr;
|
std::shared_ptr<BlockParser> currentBlockParser = nullptr;
|
||||||
@@ -204,8 +190,7 @@ private:
|
|||||||
std::shared_ptr<StrongParser> strongParser;
|
std::shared_ptr<StrongParser> strongParser;
|
||||||
|
|
||||||
// block parser have to run before
|
// block parser have to run before
|
||||||
void
|
void runLineParser(std::string& line) const
|
||||||
runLineParser(std::string& line) const
|
|
||||||
{
|
{
|
||||||
// Attention! ImageParser has to be before LinkParser
|
// Attention! ImageParser has to be before LinkParser
|
||||||
if (this->imageParser)
|
if (this->imageParser)
|
||||||
@@ -250,42 +235,27 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<BlockParser>
|
std::shared_ptr<BlockParser> getBlockParserForLine(const std::string& line
|
||||||
getBlockParserForLine(const std::string& line) const
|
) const
|
||||||
{
|
{
|
||||||
std::shared_ptr<BlockParser> parser;
|
std::shared_ptr<BlockParser> parser;
|
||||||
|
|
||||||
if (
|
if ((!this->config || (this->config->enabledParsers &
|
||||||
(
|
maddy::types::CODE_BLOCK_PARSER) != 0) &&
|
||||||
!this->config ||
|
maddy::CodeBlockParser::IsStartingLine(line))
|
||||||
(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 (
|
else if (this->config &&
|
||||||
this->config &&
|
(this->config->enabledParsers & maddy::types::LATEX_BLOCK_PARSER
|
||||||
(this->config->enabledParsers & maddy::types::LATEX_BLOCK_PARSER) != 0 &&
|
) != 0 &&
|
||||||
maddy::LatexBlockParser::IsStartingLine(line)
|
maddy::LatexBlockParser::IsStartingLine(line))
|
||||||
)
|
|
||||||
{
|
{
|
||||||
parser = std::make_shared<LatexBlockParser>(
|
parser = std::make_shared<LatexBlockParser>(nullptr, nullptr);
|
||||||
nullptr,
|
|
||||||
nullptr
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
else if (
|
else if ((!this->config || (this->config->enabledParsers &
|
||||||
(
|
maddy::types::HEADLINE_PARSER) != 0) &&
|
||||||
!this->config ||
|
maddy::HeadlineParser::IsStartingLine(line))
|
||||||
(this->config->enabledParsers & maddy::types::HEADLINE_PARSER) != 0
|
|
||||||
) &&
|
|
||||||
maddy::HeadlineParser::IsStartingLine(line)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if (!this->config || this->config->isHeadlineInlineParsingEnabled)
|
if (!this->config || this->config->isHeadlineInlineParsingEnabled)
|
||||||
{
|
{
|
||||||
@@ -297,106 +267,72 @@ private:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
parser = std::make_shared<maddy::HeadlineParser>(
|
parser =
|
||||||
nullptr,
|
std::make_shared<maddy::HeadlineParser>(nullptr, nullptr, false);
|
||||||
nullptr,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (
|
else if ((!this->config || (this->config->enabledParsers &
|
||||||
(
|
maddy::types::HORIZONTAL_LINE_PARSER) != 0) &&
|
||||||
!this->config ||
|
maddy::HorizontalLineParser::IsStartingLine(line))
|
||||||
(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 (
|
else if ((!this->config || (this->config->enabledParsers &
|
||||||
(
|
maddy::types::QUOTE_PARSER) != 0) &&
|
||||||
!this->config ||
|
maddy::QuoteParser::IsStartingLine(line))
|
||||||
(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 (
|
else if ((!this->config || (this->config->enabledParsers &
|
||||||
(
|
maddy::types::TABLE_PARSER) != 0) &&
|
||||||
!this->config ||
|
maddy::TableParser::IsStartingLine(line))
|
||||||
(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 (
|
else if ((!this->config || (this->config->enabledParsers &
|
||||||
(
|
maddy::types::CHECKLIST_PARSER) != 0) &&
|
||||||
!this->config ||
|
maddy::ChecklistParser::IsStartingLine(line))
|
||||||
(this->config->enabledParsers & maddy::types::CHECKLIST_PARSER) != 0
|
|
||||||
) &&
|
|
||||||
maddy::ChecklistParser::IsStartingLine(line)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
parser = this->createChecklistParser();
|
parser = this->createChecklistParser();
|
||||||
}
|
}
|
||||||
else if (
|
else if ((!this->config || (this->config->enabledParsers &
|
||||||
(
|
maddy::types::ORDERED_LIST_PARSER) != 0) &&
|
||||||
!this->config ||
|
maddy::OrderedListParser::IsStartingLine(line))
|
||||||
(this->config->enabledParsers & maddy::types::ORDERED_LIST_PARSER) != 0
|
|
||||||
) &&
|
|
||||||
maddy::OrderedListParser::IsStartingLine(line)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
parser = this->createOrderedListParser();
|
parser = this->createOrderedListParser();
|
||||||
}
|
}
|
||||||
else if (
|
else if ((!this->config || (this->config->enabledParsers &
|
||||||
(
|
maddy::types::UNORDERED_LIST_PARSER) != 0) &&
|
||||||
!this->config ||
|
maddy::UnorderedListParser::IsStartingLine(line))
|
||||||
(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->enabledParsers & maddy::types::HTML_PARSER) != 0 &&
|
(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 (
|
else if (maddy::ParagraphParser::IsStartingLine(line))
|
||||||
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)
|
(!this->config ||
|
||||||
|
(this->config->enabledParsers & maddy::types::PARAGRAPH_PARSER) != 0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parser;
|
return parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<BlockParser>
|
std::shared_ptr<BlockParser> createChecklistParser() const
|
||||||
createChecklistParser() const
|
|
||||||
{
|
{
|
||||||
return std::make_shared<maddy::ChecklistParser>(
|
return std::make_shared<maddy::ChecklistParser>(
|
||||||
[this](std::string& line) { this->runLineParser(line); },
|
[this](std::string& line) { this->runLineParser(line); },
|
||||||
@@ -404,13 +340,9 @@ private:
|
|||||||
{
|
{
|
||||||
std::shared_ptr<BlockParser> parser;
|
std::shared_ptr<BlockParser> parser;
|
||||||
|
|
||||||
if (
|
if ((!this->config || (this->config->enabledParsers &
|
||||||
(
|
maddy::types::CHECKLIST_PARSER) != 0) &&
|
||||||
!this->config ||
|
maddy::ChecklistParser::IsStartingLine(line))
|
||||||
(this->config->enabledParsers & maddy::types::CHECKLIST_PARSER) != 0
|
|
||||||
) &&
|
|
||||||
maddy::ChecklistParser::IsStartingLine(line)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
parser = this->createChecklistParser();
|
parser = this->createChecklistParser();
|
||||||
}
|
}
|
||||||
@@ -420,8 +352,7 @@ private:
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<BlockParser>
|
std::shared_ptr<BlockParser> createOrderedListParser() const
|
||||||
createOrderedListParser() const
|
|
||||||
{
|
{
|
||||||
return std::make_shared<maddy::OrderedListParser>(
|
return std::make_shared<maddy::OrderedListParser>(
|
||||||
[this](std::string& line) { this->runLineParser(line); },
|
[this](std::string& line) { this->runLineParser(line); },
|
||||||
@@ -429,23 +360,16 @@ private:
|
|||||||
{
|
{
|
||||||
std::shared_ptr<BlockParser> parser;
|
std::shared_ptr<BlockParser> parser;
|
||||||
|
|
||||||
if (
|
if ((!this->config || (this->config->enabledParsers &
|
||||||
(
|
maddy::types::ORDERED_LIST_PARSER) != 0) &&
|
||||||
!this->config ||
|
maddy::OrderedListParser::IsStartingLine(line))
|
||||||
(this->config->enabledParsers & maddy::types::ORDERED_LIST_PARSER) != 0
|
|
||||||
) &&
|
|
||||||
maddy::OrderedListParser::IsStartingLine(line)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
parser = this->createOrderedListParser();
|
parser = this->createOrderedListParser();
|
||||||
}
|
}
|
||||||
else if (
|
else if ((!this->config || (this->config->enabledParsers &
|
||||||
(
|
maddy::types::UNORDERED_LIST_PARSER) != 0
|
||||||
!this->config ||
|
|
||||||
(this->config->enabledParsers & maddy::types::UNORDERED_LIST_PARSER) != 0
|
|
||||||
) &&
|
) &&
|
||||||
maddy::UnorderedListParser::IsStartingLine(line)
|
maddy::UnorderedListParser::IsStartingLine(line))
|
||||||
)
|
|
||||||
{
|
{
|
||||||
parser = this->createUnorderedListParser();
|
parser = this->createUnorderedListParser();
|
||||||
}
|
}
|
||||||
@@ -455,8 +379,7 @@ private:
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<BlockParser>
|
std::shared_ptr<BlockParser> createUnorderedListParser() const
|
||||||
createUnorderedListParser() const
|
|
||||||
{
|
{
|
||||||
return std::make_shared<maddy::UnorderedListParser>(
|
return std::make_shared<maddy::UnorderedListParser>(
|
||||||
[this](std::string& line) { this->runLineParser(line); },
|
[this](std::string& line) { this->runLineParser(line); },
|
||||||
@@ -464,23 +387,16 @@ private:
|
|||||||
{
|
{
|
||||||
std::shared_ptr<BlockParser> parser;
|
std::shared_ptr<BlockParser> parser;
|
||||||
|
|
||||||
if (
|
if ((!this->config || (this->config->enabledParsers &
|
||||||
(
|
maddy::types::ORDERED_LIST_PARSER) != 0) &&
|
||||||
!this->config ||
|
maddy::OrderedListParser::IsStartingLine(line))
|
||||||
(this->config->enabledParsers & maddy::types::ORDERED_LIST_PARSER) != 0
|
|
||||||
) &&
|
|
||||||
maddy::OrderedListParser::IsStartingLine(line)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
parser = this->createOrderedListParser();
|
parser = this->createOrderedListParser();
|
||||||
}
|
}
|
||||||
else if (
|
else if ((!this->config || (this->config->enabledParsers &
|
||||||
(
|
maddy::types::UNORDERED_LIST_PARSER) != 0
|
||||||
!this->config ||
|
|
||||||
(this->config->enabledParsers & maddy::types::UNORDERED_LIST_PARSER) != 0
|
|
||||||
) &&
|
) &&
|
||||||
maddy::UnorderedListParser::IsStartingLine(line)
|
maddy::UnorderedListParser::IsStartingLine(line))
|
||||||
)
|
|
||||||
{
|
{
|
||||||
parser = this->createUnorderedListParser();
|
parser = this->createUnorderedListParser();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace maddy {
|
|||||||
|
|
||||||
namespace types {
|
namespace types {
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
/**
|
/**
|
||||||
* PARSER_TYPE
|
* PARSER_TYPE
|
||||||
*
|
*
|
||||||
@@ -46,6 +47,7 @@ enum PARSER_TYPE : uint32_t
|
|||||||
DEFAULT = 0b0111111111110111111,
|
DEFAULT = 0b0111111111110111111,
|
||||||
ALL = 0b1111111111111111111,
|
ALL = 0b1111111111111111111,
|
||||||
};
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
} // namespace types
|
} // namespace types
|
||||||
|
|
||||||
|
|||||||
@@ -31,11 +31,13 @@ public:
|
|||||||
*
|
*
|
||||||
* @method
|
* @method
|
||||||
* @param {std::function<void(std::string&)>} parseLineCallback
|
* @param {std::function<void(std::string&)>} parseLineCallback
|
||||||
* @param {std::function<std::shared_ptr<BlockParser>(const std::string& line)>} getBlockParserForLineCallback
|
* @param {std::function<std::shared_ptr<BlockParser>(const std::string&
|
||||||
|
* line)>} getBlockParserForLineCallback
|
||||||
*/
|
*/
|
||||||
QuoteParser(
|
QuoteParser(
|
||||||
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
|
||||||
)
|
)
|
||||||
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
||||||
, isStarted(false)
|
, isStarted(false)
|
||||||
@@ -51,8 +53,7 @@ public:
|
|||||||
* @param {const std::string&} line
|
* @param {const std::string&} line
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool IsStartingLine(const std::string& line)
|
||||||
IsStartingLine(const std::string& line)
|
|
||||||
{
|
{
|
||||||
static std::regex re(R"(^\>.*)");
|
static std::regex re(R"(^\>.*)");
|
||||||
return std::regex_match(line, re);
|
return std::regex_match(line, re);
|
||||||
@@ -67,8 +68,7 @@ public:
|
|||||||
* @param {std::string&} line
|
* @param {std::string&} line
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
void
|
void AddLine(std::string& line) override
|
||||||
AddLine(std::string& line) override
|
|
||||||
{
|
{
|
||||||
if (!this->isStarted)
|
if (!this->isStarted)
|
||||||
{
|
{
|
||||||
@@ -122,27 +122,14 @@ public:
|
|||||||
* @method
|
* @method
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
bool
|
bool IsFinished() const override { return this->isFinished; }
|
||||||
IsFinished() const override
|
|
||||||
{
|
|
||||||
return this->isFinished;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool
|
bool isInlineBlockAllowed() const override { return true; }
|
||||||
isInlineBlockAllowed() const override
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool isLineParserAllowed() const override { return true; }
|
||||||
isLineParserAllowed() const override
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void parseBlock(std::string& line) override
|
||||||
parseBlock(std::string& line) override
|
|
||||||
{
|
{
|
||||||
static std::regex lineRegexWithSpace(R"(^\> )");
|
static std::regex lineRegexWithSpace(R"(^\> )");
|
||||||
line = std::regex_replace(line, lineRegexWithSpace, "");
|
line = std::regex_replace(line, lineRegexWithSpace, "");
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "maddy/lineparser.h"
|
#include "maddy/lineparser.h"
|
||||||
|
|
||||||
@@ -36,10 +36,11 @@ public:
|
|||||||
* @param {std::string&} line The line to interpret
|
* @param {std::string&} line The line to interpret
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
void
|
void Parse(std::string& line) override
|
||||||
Parse(std::string& line) override
|
|
||||||
{
|
{
|
||||||
static std::regex re(R"((?!.*`.*|.*<code>.*)\~\~(?!.*`.*|.*<\/code>.*)([^\~]*)\~\~(?!.*`.*|.*<\/code>.*))");
|
static std::regex re(
|
||||||
|
R"((?!.*`.*|.*<code>.*)\~\~(?!.*`.*|.*<\/code>.*)([^\~]*)\~\~(?!.*`.*|.*<\/code>.*))"
|
||||||
|
);
|
||||||
static std::string replacement = "<s>$1</s>";
|
static std::string replacement = "<s>$1</s>";
|
||||||
|
|
||||||
line = std::regex_replace(line, re, replacement);
|
line = std::regex_replace(line, re, replacement);
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "maddy/lineparser.h"
|
#include "maddy/lineparser.h"
|
||||||
|
|
||||||
@@ -38,13 +38,15 @@ public:
|
|||||||
* @param {std::string&} line The line to interpret
|
* @param {std::string&} line The line to interpret
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
void
|
void Parse(std::string& line) override
|
||||||
Parse(std::string& line) override
|
|
||||||
{
|
{
|
||||||
static std::vector<std::regex> res
|
static std::vector<std::regex> res{
|
||||||
{
|
std::regex{
|
||||||
std::regex{R"((?!.*`.*|.*<code>.*)\*\*(?!.*`.*|.*<\/code>.*)([^\*\*]*)\*\*(?!.*`.*|.*<\/code>.*))"},
|
R"((?!.*`.*|.*<code>.*)\*\*(?!.*`.*|.*<\/code>.*)([^\*\*]*)\*\*(?!.*`.*|.*<\/code>.*))"
|
||||||
std::regex{R"((?!.*`.*|.*<code>.*)__(?!.*`.*|.*<\/code>.*)([^__]*)__(?!.*`.*|.*<\/code>.*))"}
|
},
|
||||||
|
std::regex{
|
||||||
|
R"((?!.*`.*|.*<code>.*)__(?!.*`.*|.*<\/code>.*)([^__]*)__(?!.*`.*|.*<\/code>.*))"
|
||||||
|
}
|
||||||
};
|
};
|
||||||
static std::string replacement = "<strong>$1</strong>";
|
static std::string replacement = "<strong>$1</strong>";
|
||||||
for (const auto& re : res)
|
for (const auto& re : res)
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string>
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "maddy/blockparser.h"
|
#include "maddy/blockparser.h"
|
||||||
|
|
||||||
@@ -33,11 +33,13 @@ public:
|
|||||||
*
|
*
|
||||||
* @method
|
* @method
|
||||||
* @param {std::function<void(std::string&)>} parseLineCallback
|
* @param {std::function<void(std::string&)>} parseLineCallback
|
||||||
* @param {std::function<std::shared_ptr<BlockParser>(const std::string& line)>} getBlockParserForLineCallback
|
* @param {std::function<std::shared_ptr<BlockParser>(const std::string&
|
||||||
|
* line)>} getBlockParserForLineCallback
|
||||||
*/
|
*/
|
||||||
TableParser(
|
TableParser(
|
||||||
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
|
||||||
)
|
)
|
||||||
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
||||||
, isStarted(false)
|
, isStarted(false)
|
||||||
@@ -55,8 +57,7 @@ public:
|
|||||||
* @param {const std::string&} line
|
* @param {const std::string&} line
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool IsStartingLine(const std::string& line)
|
||||||
IsStartingLine(const std::string& line)
|
|
||||||
{
|
{
|
||||||
static std::string matchString("|table>");
|
static std::string matchString("|table>");
|
||||||
return line == matchString;
|
return line == matchString;
|
||||||
@@ -71,8 +72,7 @@ public:
|
|||||||
* @param {std::string&} line
|
* @param {std::string&} line
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
void
|
void AddLine(std::string& line) override
|
||||||
AddLine(std::string& line) override
|
|
||||||
{
|
{
|
||||||
if (!this->isStarted && line == "|table>")
|
if (!this->isStarted && line == "|table>")
|
||||||
{
|
{
|
||||||
@@ -124,27 +124,14 @@ public:
|
|||||||
* @method
|
* @method
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
bool
|
bool IsFinished() const override { return this->isFinished; }
|
||||||
IsFinished() const override
|
|
||||||
{
|
|
||||||
return this->isFinished;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool
|
bool isInlineBlockAllowed() const override { return false; }
|
||||||
isInlineBlockAllowed() const override
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool isLineParserAllowed() const override { return true; }
|
||||||
isLineParserAllowed() const override
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void parseBlock(std::string&) override
|
||||||
parseBlock(std::string&) override
|
|
||||||
{
|
{
|
||||||
result << "<table>";
|
result << "<table>";
|
||||||
|
|
||||||
|
|||||||
@@ -31,11 +31,13 @@ public:
|
|||||||
*
|
*
|
||||||
* @method
|
* @method
|
||||||
* @param {std::function<void(std::string&)>} parseLineCallback
|
* @param {std::function<void(std::string&)>} parseLineCallback
|
||||||
* @param {std::function<std::shared_ptr<BlockParser>(const std::string& line)>} getBlockParserForLineCallback
|
* @param {std::function<std::shared_ptr<BlockParser>(const std::string&
|
||||||
|
* line)>} getBlockParserForLineCallback
|
||||||
*/
|
*/
|
||||||
UnorderedListParser(
|
UnorderedListParser(
|
||||||
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
|
||||||
)
|
)
|
||||||
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
|
||||||
, isStarted(false)
|
, isStarted(false)
|
||||||
@@ -51,8 +53,7 @@ public:
|
|||||||
* @param {const std::string&} line
|
* @param {const std::string&} line
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool IsStartingLine(const std::string& line)
|
||||||
IsStartingLine(const std::string& line)
|
|
||||||
{
|
{
|
||||||
static std::regex re("^[+*-] .*");
|
static std::regex re("^[+*-] .*");
|
||||||
return std::regex_match(line, re);
|
return std::regex_match(line, re);
|
||||||
@@ -64,27 +65,14 @@ public:
|
|||||||
* @method
|
* @method
|
||||||
* @return {bool}
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
bool
|
bool IsFinished() const override { return this->isFinished; }
|
||||||
IsFinished() const override
|
|
||||||
{
|
|
||||||
return this->isFinished;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool
|
bool isInlineBlockAllowed() const override { return true; }
|
||||||
isInlineBlockAllowed() const override
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool isLineParserAllowed() const override { return true; }
|
||||||
isLineParserAllowed() const override
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void parseBlock(std::string& line) override
|
||||||
parseBlock(std::string& line) override
|
|
||||||
{
|
{
|
||||||
bool isStartOfNewListItem = IsStartingLine(line);
|
bool isStartOfNewListItem = IsStartingLine(line);
|
||||||
uint32_t indentation = getIndentationWidth(line);
|
uint32_t indentation = getIndentationWidth(line);
|
||||||
@@ -105,12 +93,9 @@ protected:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (line.empty() || line.find("</li><li>") != std::string::npos ||
|
||||||
line.empty() ||
|
|
||||||
line.find("</li><li>") != std::string::npos ||
|
|
||||||
line.find("</li></ol>") != std::string::npos ||
|
line.find("</li></ol>") != std::string::npos ||
|
||||||
line.find("</li></ul>") != std::string::npos
|
line.find("</li></ul>") != std::string::npos)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
line = "</li></ul>" + line;
|
line = "</li></ul>" + line;
|
||||||
this->isFinished = true;
|
this->isFinished = true;
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ class MADDY_CHECKLISTPARSER : public ::testing::Test
|
|||||||
protected:
|
protected:
|
||||||
std::shared_ptr<maddy::ChecklistParser> clParser;
|
std::shared_ptr<maddy::ChecklistParser> clParser;
|
||||||
|
|
||||||
void
|
void SetUp() override
|
||||||
SetUp() override
|
|
||||||
{
|
{
|
||||||
std::function<std::shared_ptr<maddy::BlockParser>(const std::string& line)> getBlockParserForLineCallback = [](const std::string& line)
|
std::function<std::shared_ptr<maddy::BlockParser>(const std::string& line)>
|
||||||
|
getBlockParserForLineCallback = [](const std::string& line)
|
||||||
{
|
{
|
||||||
if (maddy::ChecklistParser::IsStartingLine(line))
|
if (maddy::ChecklistParser::IsStartingLine(line))
|
||||||
{
|
{
|
||||||
@@ -32,15 +32,16 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
this->clParser = std::make_shared<maddy::ChecklistParser>(
|
this->clParser = std::make_shared<maddy::ChecklistParser>(
|
||||||
nullptr,
|
nullptr, getBlockParserForLineCallback
|
||||||
getBlockParserForLineCallback
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
TEST_F(MADDY_CHECKLISTPARSER, IsStartingLineReturnsTrueWhenFacedWithBeginningOfList)
|
TEST_F(
|
||||||
|
MADDY_CHECKLISTPARSER, IsStartingLineReturnsTrueWhenFacedWithBeginningOfList
|
||||||
|
)
|
||||||
{
|
{
|
||||||
ASSERT_TRUE(maddy::ChecklistParser::IsStartingLine("- [ ] a"));
|
ASSERT_TRUE(maddy::ChecklistParser::IsStartingLine("- [ ] a"));
|
||||||
ASSERT_TRUE(maddy::ChecklistParser::IsStartingLine("- [x] b"));
|
ASSERT_TRUE(maddy::ChecklistParser::IsStartingLine("- [x] b"));
|
||||||
@@ -53,12 +54,11 @@ TEST_F(MADDY_CHECKLISTPARSER, IsFinishedAlwaysReturnsFalseInTheBeginning)
|
|||||||
|
|
||||||
TEST_F(MADDY_CHECKLISTPARSER, ItReplacesMarkdownWithAnHtmlChecklist)
|
TEST_F(MADDY_CHECKLISTPARSER, ItReplacesMarkdownWithAnHtmlChecklist)
|
||||||
{
|
{
|
||||||
std::vector<std::string> markdown = {
|
std::vector<std::string> markdown = {"- [ ] a", "- [x] b", ""};
|
||||||
"- [ ] a"
|
std::string expected =
|
||||||
, "- [x] b"
|
"<ul class=\"checklist\"><li><label><input type=\"checkbox\"/> "
|
||||||
, ""
|
"a</label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> "
|
||||||
};
|
"b</label></li></ul>";
|
||||||
std::string expected = "<ul class=\"checklist\"><li><label><input type=\"checkbox\"/> a</label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> b</label></li></ul>";
|
|
||||||
|
|
||||||
for (std::string md : markdown)
|
for (std::string md : markdown)
|
||||||
{
|
{
|
||||||
@@ -76,14 +76,15 @@ TEST_F(MADDY_CHECKLISTPARSER, ItReplacesMarkdownWithAnHtmlChecklist)
|
|||||||
TEST_F(MADDY_CHECKLISTPARSER, ItReplacesMarkdownWithAnHierachicalHtmlList)
|
TEST_F(MADDY_CHECKLISTPARSER, ItReplacesMarkdownWithAnHierachicalHtmlList)
|
||||||
{
|
{
|
||||||
std::vector<std::string> markdown = {
|
std::vector<std::string> markdown = {
|
||||||
"- [ ] a"
|
"- [ ] a", " - [ ] d", " - [ ] e", "- [ ] b", " - [x] c", ""
|
||||||
, " - [ ] d"
|
|
||||||
, " - [ ] e"
|
|
||||||
, "- [ ] b"
|
|
||||||
, " - [x] c"
|
|
||||||
, ""
|
|
||||||
};
|
};
|
||||||
std::string expected = "<ul class=\"checklist\"><li><label><input type=\"checkbox\"/> a<ul class=\"checklist\"><li><label><input type=\"checkbox\"/> d</label></li><li><label><input type=\"checkbox\"/> e</label></li></ul></label></li><li><label><input type=\"checkbox\"/> b<ul class=\"checklist\"><li><label><input type=\"checkbox\" checked=\"checked\"/> c</label></li></ul></label></li></ul>";
|
std::string expected =
|
||||||
|
"<ul class=\"checklist\"><li><label><input type=\"checkbox\"/> a<ul "
|
||||||
|
"class=\"checklist\"><li><label><input type=\"checkbox\"/> "
|
||||||
|
"d</label></li><li><label><input type=\"checkbox\"/> "
|
||||||
|
"e</label></li></ul></label></li><li><label><input type=\"checkbox\"/> "
|
||||||
|
"b<ul class=\"checklist\"><li><label><input type=\"checkbox\" "
|
||||||
|
"checked=\"checked\"/> c</label></li></ul></label></li></ul>";
|
||||||
|
|
||||||
for (std::string md : markdown)
|
for (std::string md : markdown)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,13 +15,9 @@ class MADDY_CODEBLOCKPARSER : public ::testing::Test
|
|||||||
protected:
|
protected:
|
||||||
std::shared_ptr<maddy::CodeBlockParser> cbParser;
|
std::shared_ptr<maddy::CodeBlockParser> cbParser;
|
||||||
|
|
||||||
void
|
void SetUp() override
|
||||||
SetUp() override
|
|
||||||
{
|
{
|
||||||
this->cbParser = std::make_shared<maddy::CodeBlockParser>(
|
this->cbParser = std::make_shared<maddy::CodeBlockParser>(nullptr, nullptr);
|
||||||
nullptr,
|
|
||||||
nullptr
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -40,13 +36,11 @@ TEST_F(MADDY_CODEBLOCKPARSER, IsFinishedReturnsFalseInTheBeginning)
|
|||||||
TEST_F(MADDY_CODEBLOCKPARSER, ItReplacesMarkdownWithAnHtmlCodeBlock)
|
TEST_F(MADDY_CODEBLOCKPARSER, ItReplacesMarkdownWithAnHtmlCodeBlock)
|
||||||
{
|
{
|
||||||
std::vector<std::string> markdown = {
|
std::vector<std::string> markdown = {
|
||||||
"```"
|
"```", "some code", "some other code", "```"
|
||||||
, "some code"
|
|
||||||
, "some other code"
|
|
||||||
, "```"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string expected = "<pre><code>\nsome code\nsome other code\n</code></pre>";
|
std::string expected =
|
||||||
|
"<pre><code>\nsome code\nsome other code\n</code></pre>";
|
||||||
|
|
||||||
for (std::string md : markdown)
|
for (std::string md : markdown)
|
||||||
{
|
{
|
||||||
@@ -63,13 +57,11 @@ TEST_F(MADDY_CODEBLOCKPARSER, ItReplacesMarkdownWithAnHtmlCodeBlock)
|
|||||||
TEST_F(MADDY_CODEBLOCKPARSER, ItShouldUseAnythingBehindFirstBackticksAsClass)
|
TEST_F(MADDY_CODEBLOCKPARSER, ItShouldUseAnythingBehindFirstBackticksAsClass)
|
||||||
{
|
{
|
||||||
std::vector<std::string> markdown = {
|
std::vector<std::string> markdown = {
|
||||||
"```cpp"
|
"```cpp", "some code", "some other code", "```"
|
||||||
, "some code"
|
|
||||||
, "some other code"
|
|
||||||
, "```"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string expected = "<pre class=\"cpp\"><code>\nsome code\nsome other code\n</code></pre>";
|
std::string expected =
|
||||||
|
"<pre class=\"cpp\"><code>\nsome code\nsome other code\n</code></pre>";
|
||||||
|
|
||||||
for (std::string md : markdown)
|
for (std::string md : markdown)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ TEST(MADDY_EMPHASIZEDPARSER, ItReplacesMarkdownWithEmphasizedHTML)
|
|||||||
TEST(MADDY_EMPHASIZEDPARSER, ItDoesNotParseInsideInlineCode)
|
TEST(MADDY_EMPHASIZEDPARSER, ItDoesNotParseInsideInlineCode)
|
||||||
{
|
{
|
||||||
std::string text = "some text `*bla*` `/**text*/` testing _it_ out";
|
std::string text = "some text `*bla*` `/**text*/` testing _it_ out";
|
||||||
std::string expected = "some text `*bla*` `/**text*/` testing <em>it</em> out";
|
std::string expected =
|
||||||
|
"some text `*bla*` `/**text*/` testing <em>it</em> out";
|
||||||
auto emphasizedParser = std::make_shared<maddy::EmphasizedParser>();
|
auto emphasizedParser = std::make_shared<maddy::EmphasizedParser>();
|
||||||
|
|
||||||
emphasizedParser->Parse(text);
|
emphasizedParser->Parse(text);
|
||||||
|
|||||||
@@ -15,19 +15,17 @@ class MADDY_HEADLINEPARSER : public ::testing::Test
|
|||||||
protected:
|
protected:
|
||||||
std::shared_ptr<maddy::HeadlineParser> hlParser;
|
std::shared_ptr<maddy::HeadlineParser> hlParser;
|
||||||
|
|
||||||
void
|
void SetUp() override
|
||||||
SetUp() override
|
|
||||||
{
|
{
|
||||||
this->hlParser = std::make_shared<maddy::HeadlineParser>(
|
this->hlParser = std::make_shared<maddy::HeadlineParser>(nullptr, nullptr);
|
||||||
nullptr,
|
|
||||||
nullptr
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
TEST_F(MADDY_HEADLINEPARSER, IsStartingLineReturnsTrueWhenFacedWithOneToSixHashes)
|
TEST_F(
|
||||||
|
MADDY_HEADLINEPARSER, IsStartingLineReturnsTrueWhenFacedWithOneToSixHashes
|
||||||
|
)
|
||||||
{
|
{
|
||||||
ASSERT_TRUE(maddy::HeadlineParser::IsStartingLine("# a"));
|
ASSERT_TRUE(maddy::HeadlineParser::IsStartingLine("# a"));
|
||||||
ASSERT_TRUE(maddy::HeadlineParser::IsStartingLine("## a"));
|
ASSERT_TRUE(maddy::HeadlineParser::IsStartingLine("## a"));
|
||||||
@@ -45,21 +43,16 @@ TEST_F(MADDY_HEADLINEPARSER, IsFinishedAlwaysReturnsTrue)
|
|||||||
TEST_F(MADDY_HEADLINEPARSER, ItReplacesMarkdownWithAnHtmlHeadline)
|
TEST_F(MADDY_HEADLINEPARSER, ItReplacesMarkdownWithAnHtmlHeadline)
|
||||||
{
|
{
|
||||||
std::vector<std::string> markdown = {
|
std::vector<std::string> markdown = {
|
||||||
"# a"
|
"# a", "## a", "### a", "#### a", "##### a", "###### a"
|
||||||
, "## a"
|
|
||||||
, "### a"
|
|
||||||
, "#### a"
|
|
||||||
, "##### a"
|
|
||||||
, "###### a"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::string> expected = {
|
std::vector<std::string> expected = {
|
||||||
"<h1>a</h1>"
|
"<h1>a</h1>",
|
||||||
, "<h2>a</h2>"
|
"<h2>a</h2>",
|
||||||
, "<h3>a</h3>"
|
"<h3>a</h3>",
|
||||||
, "<h4>a</h4>"
|
"<h4>a</h4>",
|
||||||
, "<h5>a</h5>"
|
"<h5>a</h5>",
|
||||||
, "<h6>a</h6>"
|
"<h6>a</h6>"
|
||||||
};
|
};
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 6; ++i)
|
for (uint8_t i = 0; i < 6; ++i)
|
||||||
|
|||||||
@@ -15,19 +15,18 @@ class MADDY_HORIZONTALLINEPARSER : public ::testing::Test
|
|||||||
protected:
|
protected:
|
||||||
std::shared_ptr<maddy::HorizontalLineParser> hlParser;
|
std::shared_ptr<maddy::HorizontalLineParser> hlParser;
|
||||||
|
|
||||||
void
|
void SetUp() override
|
||||||
SetUp() override
|
|
||||||
{
|
{
|
||||||
this->hlParser = std::make_shared<maddy::HorizontalLineParser>(
|
this->hlParser =
|
||||||
nullptr,
|
std::make_shared<maddy::HorizontalLineParser>(nullptr, nullptr);
|
||||||
nullptr
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
TEST_F(MADDY_HORIZONTALLINEPARSER, IsStartingLineReturnsTrueWhenFacedWithThreeDashes)
|
TEST_F(
|
||||||
|
MADDY_HORIZONTALLINEPARSER, IsStartingLineReturnsTrueWhenFacedWithThreeDashes
|
||||||
|
)
|
||||||
{
|
{
|
||||||
ASSERT_TRUE(maddy::HorizontalLineParser::IsStartingLine("---"));
|
ASSERT_TRUE(maddy::HorizontalLineParser::IsStartingLine("---"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,13 +15,9 @@ class MADDY_HTMLPARSER : public ::testing::Test
|
|||||||
protected:
|
protected:
|
||||||
std::shared_ptr<maddy::HtmlParser> pParser;
|
std::shared_ptr<maddy::HtmlParser> pParser;
|
||||||
|
|
||||||
void
|
void SetUp() override
|
||||||
SetUp() override
|
|
||||||
{
|
{
|
||||||
this->pParser = std::make_shared<maddy::HtmlParser>(
|
this->pParser = std::make_shared<maddy::HtmlParser>(nullptr, nullptr);
|
||||||
nullptr,
|
|
||||||
nullptr
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -35,11 +31,7 @@ TEST_F(MADDY_HTMLPARSER, IsFinishedReturnsFalseInTheBeginning)
|
|||||||
TEST_F(MADDY_HTMLPARSER, IsStartingLineReturnsFalseWhenFacedWithNoSmallerThan)
|
TEST_F(MADDY_HTMLPARSER, IsStartingLineReturnsFalseWhenFacedWithNoSmallerThan)
|
||||||
{
|
{
|
||||||
const std::vector<std::string> markdown = {
|
const std::vector<std::string> markdown = {
|
||||||
"> quote"
|
"> quote", "some text", "* list", "1. numbered list", "|table>"
|
||||||
, "some text"
|
|
||||||
, "* list"
|
|
||||||
, "1. numbered list"
|
|
||||||
, "|table>"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; i < markdown.size(); ++i)
|
for (size_t i = 0; i < markdown.size(); ++i)
|
||||||
@@ -58,16 +50,17 @@ TEST_F(MADDY_HTMLPARSER, IsStartingLineReturnsTrueWhenFacedWithSmallerThan)
|
|||||||
TEST_F(MADDY_HTMLPARSER, ItReplacesNoHtml)
|
TEST_F(MADDY_HTMLPARSER, ItReplacesNoHtml)
|
||||||
{
|
{
|
||||||
const std::vector<std::string> markdown{
|
const std::vector<std::string> markdown{
|
||||||
"some text in a paragraph"
|
"some text in a paragraph",
|
||||||
, ""
|
"",
|
||||||
, "<div> some HTML</div>"
|
"<div> some HTML</div>",
|
||||||
, ""
|
"",
|
||||||
, "<div>more"
|
"<div>more",
|
||||||
, "HTML"
|
"HTML",
|
||||||
, "</div>"
|
"</div>",
|
||||||
, ""
|
""
|
||||||
};
|
};
|
||||||
const std::string expected = "some text in a paragraph <div> some HTML</div><div>more HTML </div>";
|
const std::string expected =
|
||||||
|
"some text in a paragraph <div> some HTML</div><div>more HTML </div>";
|
||||||
|
|
||||||
for (std::string md : markdown)
|
for (std::string md : markdown)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
TEST(MADDY_IMAGEPARSER, ItReplacesMarkdownWithAnImage)
|
TEST(MADDY_IMAGEPARSER, ItReplacesMarkdownWithAnImage)
|
||||||
{
|
{
|
||||||
std::string text = "Some text ";
|
std::string text = "Some text ";
|
||||||
std::string expected = "Some text <img src=\"http://example.com/a.png\" alt=\"Image Title\"/>";
|
std::string expected =
|
||||||
|
"Some text <img src=\"http://example.com/a.png\" alt=\"Image Title\"/>";
|
||||||
auto imageParser = std::make_shared<maddy::ImageParser>();
|
auto imageParser = std::make_shared<maddy::ImageParser>();
|
||||||
|
|
||||||
imageParser->Parse(text);
|
imageParser->Parse(text);
|
||||||
@@ -23,8 +24,12 @@ TEST(MADDY_IMAGEPARSER, ItReplacesMarkdownWithAnImage)
|
|||||||
|
|
||||||
TEST(MADDY_IMAGEPARSER, ItReplacesMarkdownWithImages)
|
TEST(MADDY_IMAGEPARSER, ItReplacesMarkdownWithImages)
|
||||||
{
|
{
|
||||||
std::string text = "Some text  bla ";
|
std::string text =
|
||||||
std::string expected = "Some text <img src=\"http://example.com/a.png\" alt=\"Image Title\"/> bla <img src=\"http://example.com/a.png\" alt=\"Image Title\"/>";
|
"Some text  bla ";
|
||||||
|
std::string expected =
|
||||||
|
"Some text <img src=\"http://example.com/a.png\" alt=\"Image Title\"/> bla "
|
||||||
|
"<img src=\"http://example.com/a.png\" alt=\"Image Title\"/>";
|
||||||
auto imageParser = std::make_shared<maddy::ImageParser>();
|
auto imageParser = std::make_shared<maddy::ImageParser>();
|
||||||
|
|
||||||
imageParser->Parse(text);
|
imageParser->Parse(text);
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
TEST(MADDY_INLINECODEPARSER, ItReplacesMarkdownWithCodeHTML)
|
TEST(MADDY_INLINECODEPARSER, ItReplacesMarkdownWithCodeHTML)
|
||||||
{
|
{
|
||||||
std::string text = "some text `bla` text testing `it` out";
|
std::string text = "some text `bla` text testing `it` out";
|
||||||
std::string expected = "some text <code>bla</code> text testing <code>it</code> out";
|
std::string expected =
|
||||||
|
"some text <code>bla</code> text testing <code>it</code> out";
|
||||||
auto emphasizedParser = std::make_shared<maddy::InlineCodeParser>();
|
auto emphasizedParser = std::make_shared<maddy::InlineCodeParser>();
|
||||||
|
|
||||||
emphasizedParser->Parse(text);
|
emphasizedParser->Parse(text);
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
TEST(MADDY_ITALICPARSER, ItReplacesMarkdownWithItalicHTML)
|
TEST(MADDY_ITALICPARSER, ItReplacesMarkdownWithItalicHTML)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::string text = "some text *bla* text testing *it* out";
|
std::string text = "some text *bla* text testing *it* out";
|
||||||
std::string expected = "some text <i>bla</i> text testing <i>it</i> out";
|
std::string expected = "some text <i>bla</i> text testing <i>it</i> out";
|
||||||
auto italicParser = std::make_shared<maddy::ItalicParser>();
|
auto italicParser = std::make_shared<maddy::ItalicParser>();
|
||||||
|
|||||||
@@ -15,13 +15,10 @@ class MADDY_LATEXBLOCKPARSER : public ::testing::Test
|
|||||||
protected:
|
protected:
|
||||||
std::shared_ptr<maddy::LatexBlockParser> lbParser;
|
std::shared_ptr<maddy::LatexBlockParser> lbParser;
|
||||||
|
|
||||||
void
|
void SetUp() override
|
||||||
SetUp() override
|
|
||||||
{
|
{
|
||||||
this->lbParser = std::make_shared<maddy::LatexBlockParser>(
|
this->lbParser =
|
||||||
nullptr,
|
std::make_shared<maddy::LatexBlockParser>(nullptr, nullptr);
|
||||||
nullptr
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -60,9 +57,7 @@ TEST_F(MADDY_LATEXBLOCKPARSER, ItReplacesOneLineMarkdownWithALatexBlock)
|
|||||||
TEST_F(MADDY_LATEXBLOCKPARSER, ItReplacesABlockMarkdownWithALatexBlock)
|
TEST_F(MADDY_LATEXBLOCKPARSER, ItReplacesABlockMarkdownWithALatexBlock)
|
||||||
{
|
{
|
||||||
std::vector<std::string> markdown = {
|
std::vector<std::string> markdown = {
|
||||||
"$$",
|
"$$", "x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.", "$$"
|
||||||
"x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.",
|
|
||||||
"$$"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string expected = "$$\nx = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.\n$$\n";
|
std::string expected = "$$\nx = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.\n$$\n";
|
||||||
@@ -82,9 +77,7 @@ TEST_F(MADDY_LATEXBLOCKPARSER, ItReplacesABlockMarkdownWithALatexBlock)
|
|||||||
TEST_F(MADDY_LATEXBLOCKPARSER, ItReplacesAMultilineBlockMarkdownWithALatexBlock)
|
TEST_F(MADDY_LATEXBLOCKPARSER, ItReplacesAMultilineBlockMarkdownWithALatexBlock)
|
||||||
{
|
{
|
||||||
std::vector<std::string> markdown = {
|
std::vector<std::string> markdown = {
|
||||||
"$$",
|
"$$", "x = {-b \\pm \\sqrt{b^2-4ac}", "\\over 2a}.$$"
|
||||||
"x = {-b \\pm \\sqrt{b^2-4ac}",
|
|
||||||
"\\over 2a}.$$"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string expected = "$$\nx = {-b \\pm \\sqrt{b^2-4ac}\n\\over 2a}.$$\n";
|
std::string expected = "$$\nx = {-b \\pm \\sqrt{b^2-4ac}\n\\over 2a}.$$\n";
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
TEST(MADDY_LINKPARSER, ItReplacesMarkdownWithALink)
|
TEST(MADDY_LINKPARSER, ItReplacesMarkdownWithALink)
|
||||||
{
|
{
|
||||||
std::string text = "Some text [Link Title](http://example.com)";
|
std::string text = "Some text [Link Title](http://example.com)";
|
||||||
std::string expected = "Some text <a href=\"http://example.com\">Link Title</a>";
|
std::string expected =
|
||||||
|
"Some text <a href=\"http://example.com\">Link Title</a>";
|
||||||
auto linkParser = std::make_shared<maddy::LinkParser>();
|
auto linkParser = std::make_shared<maddy::LinkParser>();
|
||||||
|
|
||||||
linkParser->Parse(text);
|
linkParser->Parse(text);
|
||||||
@@ -23,8 +24,12 @@ TEST(MADDY_LINKPARSER, ItReplacesMarkdownWithALink)
|
|||||||
|
|
||||||
TEST(MADDY_LINKPARSER, ItReplacesMarkdownWithLinks)
|
TEST(MADDY_LINKPARSER, ItReplacesMarkdownWithLinks)
|
||||||
{
|
{
|
||||||
std::string text = "Some text [Link Title](http://example.com) bla [Link Title](http://example.com)";
|
std::string text =
|
||||||
std::string expected = "Some text <a href=\"http://example.com\">Link Title</a> bla <a href=\"http://example.com\">Link Title</a>";
|
"Some text [Link Title](http://example.com) bla [Link "
|
||||||
|
"Title](http://example.com)";
|
||||||
|
std::string expected =
|
||||||
|
"Some text <a href=\"http://example.com\">Link Title</a> bla <a "
|
||||||
|
"href=\"http://example.com\">Link Title</a>";
|
||||||
auto linkParser = std::make_shared<maddy::LinkParser>();
|
auto linkParser = std::make_shared<maddy::LinkParser>();
|
||||||
|
|
||||||
linkParser->Parse(text);
|
linkParser->Parse(text);
|
||||||
@@ -34,7 +39,8 @@ TEST(MADDY_LINKPARSER, ItReplacesMarkdownWithLinks)
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class DISABLED_MADDY_LINKPARSER : public ::testing::Test { };
|
class DISABLED_MADDY_LINKPARSER : public ::testing::Test
|
||||||
|
{};
|
||||||
|
|
||||||
// This test is disabled for now, so make sure, to first run the ImageParser
|
// This test is disabled for now, so make sure, to first run the ImageParser
|
||||||
// before using the LinkParser
|
// before using the LinkParser
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ class MADDY_ORDEREDLISTPARSER : public ::testing::Test
|
|||||||
protected:
|
protected:
|
||||||
std::shared_ptr<maddy::OrderedListParser> olParser;
|
std::shared_ptr<maddy::OrderedListParser> olParser;
|
||||||
|
|
||||||
void
|
void SetUp() override
|
||||||
SetUp() override
|
|
||||||
{
|
{
|
||||||
std::function<std::shared_ptr<maddy::BlockParser>(const std::string& line)> getBlockParserForLineCallback = [](const std::string& line)
|
std::function<std::shared_ptr<maddy::BlockParser>(const std::string& line)>
|
||||||
|
getBlockParserForLineCallback = [](const std::string& line)
|
||||||
{
|
{
|
||||||
if (maddy::OrderedListParser::IsStartingLine(line))
|
if (maddy::OrderedListParser::IsStartingLine(line))
|
||||||
{
|
{
|
||||||
@@ -32,15 +32,16 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
this->olParser = std::make_shared<maddy::OrderedListParser>(
|
this->olParser = std::make_shared<maddy::OrderedListParser>(
|
||||||
nullptr,
|
nullptr, getBlockParserForLineCallback
|
||||||
getBlockParserForLineCallback
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
TEST_F(MADDY_ORDEREDLISTPARSER, IsStartingLineReturnsTrueWhenFacedWithBeginningOfList)
|
TEST_F(
|
||||||
|
MADDY_ORDEREDLISTPARSER, IsStartingLineReturnsTrueWhenFacedWithBeginningOfList
|
||||||
|
)
|
||||||
{
|
{
|
||||||
ASSERT_TRUE(maddy::OrderedListParser::IsStartingLine("1. a"));
|
ASSERT_TRUE(maddy::OrderedListParser::IsStartingLine("1. a"));
|
||||||
}
|
}
|
||||||
@@ -52,11 +53,7 @@ TEST_F(MADDY_ORDEREDLISTPARSER, IsFinishedAlwaysReturnsFalseInTheBeginning)
|
|||||||
|
|
||||||
TEST_F(MADDY_ORDEREDLISTPARSER, ItReplacesMarkdownWithAnHtmlOrderedList)
|
TEST_F(MADDY_ORDEREDLISTPARSER, ItReplacesMarkdownWithAnHtmlOrderedList)
|
||||||
{
|
{
|
||||||
std::vector<std::string> markdown = {
|
std::vector<std::string> markdown = {"1. a", "* b", ""};
|
||||||
"1. a"
|
|
||||||
, "* b"
|
|
||||||
, ""
|
|
||||||
};
|
|
||||||
std::string expected = "<ol><li>a</li><li>b</li></ol>";
|
std::string expected = "<ol><li>a</li><li>b</li></ol>";
|
||||||
|
|
||||||
for (std::string md : markdown)
|
for (std::string md : markdown)
|
||||||
@@ -75,14 +72,11 @@ TEST_F(MADDY_ORDEREDLISTPARSER, ItReplacesMarkdownWithAnHtmlOrderedList)
|
|||||||
TEST_F(MADDY_ORDEREDLISTPARSER, ItReplacesMarkdownWithAnHierachicalHtmlList)
|
TEST_F(MADDY_ORDEREDLISTPARSER, ItReplacesMarkdownWithAnHierachicalHtmlList)
|
||||||
{
|
{
|
||||||
std::vector<std::string> markdown = {
|
std::vector<std::string> markdown = {
|
||||||
"1. a"
|
"1. a", " 1. d", " * e", "* b", " 1. c", ""
|
||||||
, " 1. d"
|
|
||||||
, " * e"
|
|
||||||
, "* b"
|
|
||||||
, " 1. c"
|
|
||||||
, ""
|
|
||||||
};
|
};
|
||||||
std::string expected = "<ol><li>a<ol><li>d</li><li>e</li></ol></li><li>b<ol><li>c</li></ol></li></ol>";
|
std::string expected =
|
||||||
|
"<ol><li>a<ol><li>d</li><li>e</li></ol></li><li>b<ol><li>c</li></ol></li></"
|
||||||
|
"ol>";
|
||||||
|
|
||||||
for (std::string md : markdown)
|
for (std::string md : markdown)
|
||||||
{
|
{
|
||||||
@@ -97,14 +91,11 @@ TEST_F(MADDY_ORDEREDLISTPARSER, ItReplacesMarkdownWithAnHierachicalHtmlList)
|
|||||||
ASSERT_EQ(expected, outputString);
|
ASSERT_EQ(expected, outputString);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MADDY_ORDEREDLISTPARSER, ItReplacesNumberedMarkdownListWithAnHtmlOrderedList)
|
TEST_F(
|
||||||
|
MADDY_ORDEREDLISTPARSER, ItReplacesNumberedMarkdownListWithAnHtmlOrderedList
|
||||||
|
)
|
||||||
{
|
{
|
||||||
std::vector<std::string> markdown = {
|
std::vector<std::string> markdown = {"1. a", "94. b", "103. c", ""};
|
||||||
"1. a"
|
|
||||||
, "94. b"
|
|
||||||
, "103. c"
|
|
||||||
, ""
|
|
||||||
};
|
|
||||||
std::string expected = "<ol><li>a</li><li>b</li><li>c</li></ol>";
|
std::string expected = "<ol><li>a</li><li>b</li><li>c</li></ol>";
|
||||||
|
|
||||||
for (std::string md : markdown)
|
for (std::string md : markdown)
|
||||||
|
|||||||
@@ -15,14 +15,10 @@ class MADDY_PARAGRAPHPARSER : public ::testing::Test
|
|||||||
protected:
|
protected:
|
||||||
std::shared_ptr<maddy::ParagraphParser> pParser;
|
std::shared_ptr<maddy::ParagraphParser> pParser;
|
||||||
|
|
||||||
void
|
void SetUp() override
|
||||||
SetUp() override
|
|
||||||
{
|
{
|
||||||
this->pParser = std::make_shared<maddy::ParagraphParser>(
|
this->pParser =
|
||||||
nullptr,
|
std::make_shared<maddy::ParagraphParser>(nullptr, nullptr, true);
|
||||||
nullptr,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -40,11 +36,7 @@ TEST_F(MADDY_PARAGRAPHPARSER, IsFinishedReturnsFalseInTheBeginning)
|
|||||||
|
|
||||||
TEST_F(MADDY_PARAGRAPHPARSER, ItReplacesMarkdownWithAnHtmlLine)
|
TEST_F(MADDY_PARAGRAPHPARSER, ItReplacesMarkdownWithAnHtmlLine)
|
||||||
{
|
{
|
||||||
std::vector<std::string> markdown = {
|
std::vector<std::string> markdown = {"Some text", "and some other text", ""};
|
||||||
"Some text"
|
|
||||||
, "and some other text"
|
|
||||||
, ""
|
|
||||||
};
|
|
||||||
std::string expected = "<p>Some text and some other text </p>";
|
std::string expected = "<p>Some text and some other text </p>";
|
||||||
|
|
||||||
for (std::string md : markdown)
|
for (std::string md : markdown)
|
||||||
|
|||||||
@@ -3,10 +3,11 @@
|
|||||||
* LICENSE file.
|
* LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "maddy/test_maddy_parser.h"
|
||||||
|
|
||||||
#include "gmock/gmock.h"
|
#include "gmock/gmock.h"
|
||||||
|
|
||||||
#include "maddy/parser.h"
|
#include "maddy/parser.h"
|
||||||
#include "maddy/test_maddy_parser.h"
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -53,8 +54,8 @@ TEST(MADDY_PARSER, ItShouldParseWithBitwiseConfig)
|
|||||||
TEST(MADDY_PARSER, ItShouldParseWithSmallConfig)
|
TEST(MADDY_PARSER, ItShouldParseWithSmallConfig)
|
||||||
{
|
{
|
||||||
auto config = std::make_shared<maddy::ParserConfig>();
|
auto config = std::make_shared<maddy::ParserConfig>();
|
||||||
config->enabledParsers = maddy::types::EMPHASIZED_PARSER |
|
config->enabledParsers =
|
||||||
maddy::types::STRONG_PARSER;
|
maddy::types::EMPHASIZED_PARSER | maddy::types::STRONG_PARSER;
|
||||||
|
|
||||||
auto parser = std::make_shared<maddy::Parser>(config);
|
auto parser = std::make_shared<maddy::Parser>(config);
|
||||||
|
|
||||||
@@ -70,7 +71,8 @@ TEST(MADDY_PARSER, ItShouldParseInlineCodeInHeadlines)
|
|||||||
const std::string headlineTest = R"(
|
const std::string headlineTest = R"(
|
||||||
# Some **test** markdown
|
# Some **test** markdown
|
||||||
)";
|
)";
|
||||||
const std::string expectedHTML = "<h1>Some <strong>test</strong> markdown</h1>";
|
const std::string expectedHTML =
|
||||||
|
"<h1>Some <strong>test</strong> markdown</h1>";
|
||||||
std::stringstream markdown(headlineTest);
|
std::stringstream markdown(headlineTest);
|
||||||
|
|
||||||
auto parser = std::make_shared<maddy::Parser>();
|
auto parser = std::make_shared<maddy::Parser>();
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
const std::string testMarkdown = "# This is a test\n\
|
const std::string testMarkdown =
|
||||||
|
"# This is a test\n\
|
||||||
\n\
|
\n\
|
||||||
This should result in a praragraph\n\
|
This should result in a praragraph\n\
|
||||||
it's that simple.\n\
|
it's that simple.\n\
|
||||||
@@ -69,6 +70,71 @@ foot a|foot b|foot c\n\
|
|||||||
\n\
|
\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 =
|
||||||
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>";
|
"<h1>This is a test</h1><p>This should result in a praragraph it's that "
|
||||||
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/>";
|
"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 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/>";
|
||||||
|
|||||||
@@ -15,19 +15,17 @@ class MADDY_QUOTEPARSER : public ::testing::Test
|
|||||||
protected:
|
protected:
|
||||||
std::shared_ptr<maddy::QuoteParser> quoteParser;
|
std::shared_ptr<maddy::QuoteParser> quoteParser;
|
||||||
|
|
||||||
void
|
void SetUp() override
|
||||||
SetUp() override
|
|
||||||
{
|
{
|
||||||
this->quoteParser = std::make_shared<maddy::QuoteParser>(
|
this->quoteParser = std::make_shared<maddy::QuoteParser>(nullptr, nullptr);
|
||||||
nullptr,
|
|
||||||
nullptr
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
TEST_F(MADDY_QUOTEPARSER, IsStartingLineReturnsTrueWhenFacedWithBeginningOfAQuote)
|
TEST_F(
|
||||||
|
MADDY_QUOTEPARSER, IsStartingLineReturnsTrueWhenFacedWithBeginningOfAQuote
|
||||||
|
)
|
||||||
{
|
{
|
||||||
ASSERT_TRUE(maddy::QuoteParser::IsStartingLine("> a"));
|
ASSERT_TRUE(maddy::QuoteParser::IsStartingLine("> a"));
|
||||||
}
|
}
|
||||||
@@ -39,13 +37,7 @@ TEST_F(MADDY_QUOTEPARSER, IsFinishedAlwaysReturnsFalseInTheBeginning)
|
|||||||
|
|
||||||
TEST_F(MADDY_QUOTEPARSER, ItReplacesMarkdownWithAnHtmlBlockQuote)
|
TEST_F(MADDY_QUOTEPARSER, ItReplacesMarkdownWithAnHtmlBlockQuote)
|
||||||
{
|
{
|
||||||
std::vector<std::string> markdown = {
|
std::vector<std::string> markdown = {"> a", "> b", ">", "> c", ""};
|
||||||
"> a"
|
|
||||||
, "> b"
|
|
||||||
, ">"
|
|
||||||
, "> c"
|
|
||||||
, ""
|
|
||||||
};
|
|
||||||
std::string expected = "<blockquote>a b c </blockquote>";
|
std::string expected = "<blockquote>a b c </blockquote>";
|
||||||
|
|
||||||
for (std::string md : markdown)
|
for (std::string md : markdown)
|
||||||
|
|||||||
@@ -23,8 +23,10 @@ TEST(MADDY_STRIKETHROUGHPARSER, ItReplacesMarkdownWithStrikeThroughHTML)
|
|||||||
|
|
||||||
TEST(MADDY_STRIKETHROUGHPARSER, ItDoesNotParseInsideInlineCode)
|
TEST(MADDY_STRIKETHROUGHPARSER, ItDoesNotParseInsideInlineCode)
|
||||||
{
|
{
|
||||||
std::string text = "some text `~~bla~~` ` ~~text~~ ` testing <code>~~it~~</code> out";
|
std::string text =
|
||||||
std::string expected = "some text `~~bla~~` ` ~~text~~ ` testing <code>~~it~~</code> out";
|
"some text `~~bla~~` ` ~~text~~ ` testing <code>~~it~~</code> out";
|
||||||
|
std::string expected =
|
||||||
|
"some text `~~bla~~` ` ~~text~~ ` testing <code>~~it~~</code> out";
|
||||||
auto strikeThroughParser = std::make_shared<maddy::StrikeThroughParser>();
|
auto strikeThroughParser = std::make_shared<maddy::StrikeThroughParser>();
|
||||||
|
|
||||||
strikeThroughParser->Parse(text);
|
strikeThroughParser->Parse(text);
|
||||||
|
|||||||
@@ -18,16 +18,11 @@ TEST(MADDY_STRONGPARSER, ItReplacesMarkdownWithStrongHTML)
|
|||||||
std::string expected;
|
std::string expected;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<testIt> tests
|
std::vector<testIt> tests{
|
||||||
{
|
{"some text **bla** text testing **it** out",
|
||||||
{
|
"some text <strong>bla</strong> text testing <strong>it</strong> out"},
|
||||||
"some text **bla** text testing **it** out",
|
{"some text __bla__ text testing __it__ out",
|
||||||
"some text <strong>bla</strong> text testing <strong>it</strong> out"
|
"some text <strong>bla</strong> text testing <strong>it</strong> out"},
|
||||||
},
|
|
||||||
{
|
|
||||||
"some text __bla__ text testing __it__ out",
|
|
||||||
"some text <strong>bla</strong> text testing <strong>it</strong> out"
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
auto strongParser = std::make_shared<maddy::StrongParser>();
|
auto strongParser = std::make_shared<maddy::StrongParser>();
|
||||||
@@ -47,16 +42,11 @@ TEST(MADDY_STRONGPARSER, ItReplacesEmphasizedMarkdownNotWithStrongHTML)
|
|||||||
std::string expected;
|
std::string expected;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<testIt> tests
|
std::vector<testIt> tests{
|
||||||
{
|
{"some text *bla* text testing **it** out",
|
||||||
{
|
"some text *bla* text testing <strong>it</strong> out"},
|
||||||
"some text *bla* text testing **it** out",
|
{"some text _bla_ text testing __it__ out",
|
||||||
"some text *bla* text testing <strong>it</strong> out"
|
"some text _bla_ text testing <strong>it</strong> out"},
|
||||||
},
|
|
||||||
{
|
|
||||||
"some text _bla_ text testing __it__ out",
|
|
||||||
"some text _bla_ text testing <strong>it</strong> out"
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
auto strongParser = std::make_shared<maddy::StrongParser>();
|
auto strongParser = std::make_shared<maddy::StrongParser>();
|
||||||
@@ -76,16 +66,13 @@ TEST(MADDY_STRONGPARSER, ItDoesNotParseInsideInlineCode)
|
|||||||
std::string expected;
|
std::string expected;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<testIt> tests
|
std::vector<testIt> tests{
|
||||||
{
|
|
||||||
{
|
{
|
||||||
"some text **bla** `/**text**/` testing `**it**` out",
|
"some text **bla** `/**text**/` testing `**it**` out",
|
||||||
"some text **bla** `/**text**/` testing `**it**` out",
|
"some text **bla** `/**text**/` testing `**it**` out",
|
||||||
},
|
},
|
||||||
{
|
{"some text _bla_ text testing __it__ out",
|
||||||
"some text _bla_ text testing __it__ out",
|
"some text _bla_ text testing <strong>it</strong> out"},
|
||||||
"some text _bla_ text testing <strong>it</strong> out"
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
auto strongParser = std::make_shared<maddy::StrongParser>();
|
auto strongParser = std::make_shared<maddy::StrongParser>();
|
||||||
|
|||||||
@@ -15,19 +15,17 @@ class MADDY_TABLEPARSER : public ::testing::Test
|
|||||||
protected:
|
protected:
|
||||||
std::shared_ptr<maddy::TableParser> tableParser;
|
std::shared_ptr<maddy::TableParser> tableParser;
|
||||||
|
|
||||||
void
|
void SetUp() override
|
||||||
SetUp() override
|
|
||||||
{
|
{
|
||||||
this->tableParser = std::make_shared<maddy::TableParser>(
|
this->tableParser = std::make_shared<maddy::TableParser>(nullptr, nullptr);
|
||||||
nullptr,
|
|
||||||
nullptr
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
TEST_F(MADDY_TABLEPARSER, IsStartingLineReturnsTrueWhenFacedWithTheBeginningOfATable)
|
TEST_F(
|
||||||
|
MADDY_TABLEPARSER, IsStartingLineReturnsTrueWhenFacedWithTheBeginningOfATable
|
||||||
|
)
|
||||||
{
|
{
|
||||||
ASSERT_EQ(true, maddy::TableParser::IsStartingLine("|table>"));
|
ASSERT_EQ(true, maddy::TableParser::IsStartingLine("|table>"));
|
||||||
}
|
}
|
||||||
@@ -40,16 +38,21 @@ TEST_F(MADDY_TABLEPARSER, IsFinishedReturnsFalseInTheBeginning)
|
|||||||
TEST_F(MADDY_TABLEPARSER, ItReplacesMarkdownWithAnHtmlTable)
|
TEST_F(MADDY_TABLEPARSER, ItReplacesMarkdownWithAnHtmlTable)
|
||||||
{
|
{
|
||||||
std::vector<std::string> markdown = {
|
std::vector<std::string> markdown = {
|
||||||
"|table>"
|
"|table>",
|
||||||
, "Left header|middle header|last header"
|
"Left header|middle header|last header",
|
||||||
, "- | - | -"
|
"- | - | -",
|
||||||
, "cell 1|cell 2|cell 3"
|
"cell 1|cell 2|cell 3",
|
||||||
, "cell 4|cell 5|cell 6"
|
"cell 4|cell 5|cell 6",
|
||||||
, "- | - | -"
|
"- | - | -",
|
||||||
, "foot a|foot b|foot c"
|
"foot a|foot b|foot c",
|
||||||
, "|<table"
|
"|<table"
|
||||||
};
|
};
|
||||||
std::string expected = "<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 2</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>";
|
std::string expected =
|
||||||
|
"<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 2</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>";
|
||||||
|
|
||||||
for (std::string md : markdown)
|
for (std::string md : markdown)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ class MADDY_UNORDEREDLISTPARSER : public ::testing::Test
|
|||||||
protected:
|
protected:
|
||||||
std::shared_ptr<maddy::UnorderedListParser> ulParser;
|
std::shared_ptr<maddy::UnorderedListParser> ulParser;
|
||||||
|
|
||||||
void
|
void SetUp() override
|
||||||
SetUp() override
|
|
||||||
{
|
{
|
||||||
std::function<std::shared_ptr<maddy::BlockParser>(const std::string& line)> getBlockParserForLineCallback = [](const std::string& line)
|
std::function<std::shared_ptr<maddy::BlockParser>(const std::string& line)>
|
||||||
|
getBlockParserForLineCallback = [](const std::string& line)
|
||||||
{
|
{
|
||||||
if (maddy::UnorderedListParser::IsStartingLine(line))
|
if (maddy::UnorderedListParser::IsStartingLine(line))
|
||||||
{
|
{
|
||||||
@@ -32,15 +32,17 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
this->ulParser = std::make_shared<maddy::UnorderedListParser>(
|
this->ulParser = std::make_shared<maddy::UnorderedListParser>(
|
||||||
nullptr,
|
nullptr, getBlockParserForLineCallback
|
||||||
getBlockParserForLineCallback
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
TEST_F(MADDY_UNORDEREDLISTPARSER, IsStartingLineReturnsTrueWhenFacedWithBeginningOfList)
|
TEST_F(
|
||||||
|
MADDY_UNORDEREDLISTPARSER,
|
||||||
|
IsStartingLineReturnsTrueWhenFacedWithBeginningOfList
|
||||||
|
)
|
||||||
{
|
{
|
||||||
ASSERT_TRUE(maddy::UnorderedListParser::IsStartingLine("* a"));
|
ASSERT_TRUE(maddy::UnorderedListParser::IsStartingLine("* a"));
|
||||||
}
|
}
|
||||||
@@ -53,16 +55,11 @@ TEST_F(MADDY_UNORDEREDLISTPARSER, IsFinishedAlwaysReturnsFalseInTheBeginning)
|
|||||||
TEST_F(MADDY_UNORDEREDLISTPARSER, ItReplacesMarkdownWithAnHtmlUnorderedList)
|
TEST_F(MADDY_UNORDEREDLISTPARSER, ItReplacesMarkdownWithAnHtmlUnorderedList)
|
||||||
{
|
{
|
||||||
std::vector<std::string> markdown = {
|
std::vector<std::string> markdown = {
|
||||||
"* a"
|
"* a", "* b", "- c", "- d", "+ e", "+ f", "* g", ""
|
||||||
, "* b"
|
|
||||||
, "- c"
|
|
||||||
, "- d"
|
|
||||||
, "+ e"
|
|
||||||
, "+ f"
|
|
||||||
, "* g"
|
|
||||||
, ""
|
|
||||||
};
|
};
|
||||||
std::string expected = "<ul><li>a</li><li>b</li><li>c</li><li>d</li><li>e</li><li>f</li><li>g</li></ul>";
|
std::string expected =
|
||||||
|
"<ul><li>a</li><li>b</li><li>c</li><li>d</li><li>e</li><li>f</li><li>g</"
|
||||||
|
"li></ul>";
|
||||||
|
|
||||||
for (std::string md : markdown)
|
for (std::string md : markdown)
|
||||||
{
|
{
|
||||||
@@ -80,17 +77,11 @@ TEST_F(MADDY_UNORDEREDLISTPARSER, ItReplacesMarkdownWithAnHtmlUnorderedList)
|
|||||||
TEST_F(MADDY_UNORDEREDLISTPARSER, ItReplacesMarkdownWithAnHierachicalHtmlList)
|
TEST_F(MADDY_UNORDEREDLISTPARSER, ItReplacesMarkdownWithAnHierachicalHtmlList)
|
||||||
{
|
{
|
||||||
std::vector<std::string> markdown = {
|
std::vector<std::string> markdown = {
|
||||||
"* a"
|
"* a", " * d", " * e", "* b", " * c", " + x", " + y", " - z", ""
|
||||||
, " * d"
|
|
||||||
, " * e"
|
|
||||||
, "* b"
|
|
||||||
, " * c"
|
|
||||||
, " + x"
|
|
||||||
, " + y"
|
|
||||||
, " - z"
|
|
||||||
, ""
|
|
||||||
};
|
};
|
||||||
std::string expected = "<ul><li>a<ul><li>d</li><li>e</li></ul></li><li>b<ul><li>c</li><li>x</li><li>y</li><li>z</li></ul></li></ul>";
|
std::string expected =
|
||||||
|
"<ul><li>a<ul><li>d</li><li>e</li></ul></li><li>b<ul><li>c</li><li>x</"
|
||||||
|
"li><li>y</li><li>z</li></ul></li></ul>";
|
||||||
|
|
||||||
for (std::string md : markdown)
|
for (std::string md : markdown)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
int main (int argc, char** argv) {
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
::testing::GTEST_FLAG(throw_on_failure) = true;
|
::testing::GTEST_FLAG(throw_on_failure) = true;
|
||||||
::testing::InitGoogleMock(&argc, argv);
|
::testing::InitGoogleMock(&argc, argv);
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
|
|||||||
143
tools/format.py
Normal file
143
tools/format.py
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
import glob
|
||||||
|
import os
|
||||||
|
import shlex
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# required clang-format version
|
||||||
|
REQUIRED_VERSION = "18.1.3"
|
||||||
|
|
||||||
|
def check_clang_format_version():
|
||||||
|
"""
|
||||||
|
Check if the installed clang-format version matches the required version.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
SystemExit: If the version does not match the required version or if
|
||||||
|
there is an error checking the version.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
result = subprocess.run(
|
||||||
|
['clang-format', '--version'],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
text=True,
|
||||||
|
check=True
|
||||||
|
)
|
||||||
|
version_out = result.stdout.strip().split()
|
||||||
|
|
||||||
|
version_line = '0.0.0'
|
||||||
|
is_next = False
|
||||||
|
|
||||||
|
for vo in version_out:
|
||||||
|
if vo == 'version':
|
||||||
|
is_next = True
|
||||||
|
continue
|
||||||
|
if is_next:
|
||||||
|
version_line = vo
|
||||||
|
break
|
||||||
|
|
||||||
|
if version_line != REQUIRED_VERSION:
|
||||||
|
print(f"Error: Required clang-format version is "
|
||||||
|
f"{REQUIRED_VERSION}, but found {version_line}.")
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print('clang-format version equals the required version.')
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print(f"Error checking clang-format version: {e.stderr}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
def format_files(dry_run):
|
||||||
|
"""
|
||||||
|
Format .h and .cpp files in specified directories using clang-format.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
dry_run (bool): If True, performs a dry run to check for formatting
|
||||||
|
issues without modifying files. If False, formats
|
||||||
|
the files in place.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
subprocess.CalledProcessError: If there is an error running clang-format
|
||||||
|
during the actual formatting process.
|
||||||
|
"""
|
||||||
|
patterns = [
|
||||||
|
"include/**/*.h",
|
||||||
|
"tests/**/*.h",
|
||||||
|
"tests/**/*.cpp",
|
||||||
|
]
|
||||||
|
|
||||||
|
files_to_format = []
|
||||||
|
for pattern in patterns:
|
||||||
|
matched_files = glob.glob(pattern, recursive=True)
|
||||||
|
files_to_format.extend(matched_files)
|
||||||
|
|
||||||
|
if not files_to_format:
|
||||||
|
print("No files to format.")
|
||||||
|
return
|
||||||
|
|
||||||
|
# Create a space-separated string of files
|
||||||
|
patterns_arg = ' '.join(file.replace('\\', '/') for file in files_to_format)
|
||||||
|
|
||||||
|
cwd = os.getcwd()
|
||||||
|
|
||||||
|
if dry_run:
|
||||||
|
# Check for changes without modifying the files
|
||||||
|
command = f'clang-format --style=file --dry-run --Werror {patterns_arg}'
|
||||||
|
result = subprocess.run(
|
||||||
|
shlex.split(command),
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
text=True,
|
||||||
|
cwd=cwd
|
||||||
|
)
|
||||||
|
if result.returncode != 0:
|
||||||
|
print("Files that need formatting:")
|
||||||
|
print(result.stdout)
|
||||||
|
print("Error output:")
|
||||||
|
print(result.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print("no changes found")
|
||||||
|
else:
|
||||||
|
# Format the files in place
|
||||||
|
command = f'clang-format --style=file -i {patterns_arg}'
|
||||||
|
result = subprocess.run(
|
||||||
|
shlex.split(command),
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
text=True,
|
||||||
|
cwd=cwd
|
||||||
|
)
|
||||||
|
if result.returncode != 0:
|
||||||
|
print("Error formatting files:")
|
||||||
|
print(result.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print('formatting done')
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""
|
||||||
|
Main function to handle command-line arguments and invoke formatting.
|
||||||
|
|
||||||
|
Checks for the required command-line argument, verifies the clang-format
|
||||||
|
version, and calls the format_files function to format the code.
|
||||||
|
"""
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print(
|
||||||
|
"Usage: python check_clang_format.py <dry_run|format>"
|
||||||
|
)
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print(f"Running format with {sys.argv[1]}")
|
||||||
|
|
||||||
|
dry_run = False
|
||||||
|
if sys.argv[1] == "dry_run":
|
||||||
|
dry_run = True
|
||||||
|
elif sys.argv[1] != "format":
|
||||||
|
print("Invalid argument. Use 'dry_run' or 'format'.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
check_clang_format_version()
|
||||||
|
format_files(dry_run)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user