mirror of
https://github.com/quitesimpleorg/qsmaddy.git
synced 2024-12-22 03:09:50 +01:00
Merge branch 'master' into add_italic
This commit is contained in:
commit
78652f64d5
1
AUTHORS
1
AUTHORS
@ -5,3 +5,4 @@ licensing terms detailed in LICENSE.
|
||||
a license to everyone to use it as detailed in LICENSE.)
|
||||
|
||||
M. Petra Baranski (info@progsource.de)
|
||||
Patrick José Pereira (patrickelectric@gmail.com)
|
||||
|
@ -221,10 +221,12 @@ results in
|
||||
|
||||
```
|
||||
**bold text**
|
||||
__bold text__
|
||||
```
|
||||
results in
|
||||
```html
|
||||
<strong>bold text</strong>
|
||||
<strong>bold text</strong>
|
||||
```
|
||||
|
||||
## italic
|
||||
|
@ -30,9 +30,9 @@ public:
|
||||
/**
|
||||
* Parse
|
||||
*
|
||||
* From Markdown: `text **text**`
|
||||
* From Markdown: `text **text** __text__`
|
||||
*
|
||||
* To HTML: `text <strong>text</strong>`
|
||||
* To HTML: `text <strong>text</strong> <strong>text</strong>`
|
||||
*
|
||||
* @method
|
||||
* @param {std::string&} line The line to interpret
|
||||
@ -41,10 +41,16 @@ public:
|
||||
void
|
||||
Parse(std::string& line) override
|
||||
{
|
||||
static std::regex re("(?!.*`.*|.*<code>.*)\\*\\*(?!.*`.*|.*<\\/code>.*)([^\\*\\*]*)\\*\\*(?!.*`.*|.*<\\/code>.*)");
|
||||
static std::vector<std::regex> res
|
||||
{
|
||||
std::regex{"(?!.*`.*|.*<code>.*)\\*\\*(?!.*`.*|.*<\\/code>.*)([^\\*\\*]*)\\*\\*(?!.*`.*|.*<\\/code>.*)"},
|
||||
std::regex{"(?!.*`.*|.*<code>.*)\\_\\_(?!.*`.*|.*<\\/code>.*)([^\\_\\_]*)\\_\\_(?!.*`.*|.*<\\/code>.*)"}
|
||||
};
|
||||
static std::string replacement = "<strong>$1</strong>";
|
||||
|
||||
line = std::regex_replace(line, re, replacement);
|
||||
for (const auto& re : res)
|
||||
{
|
||||
line = std::regex_replace(line, re, replacement);
|
||||
}
|
||||
}
|
||||
}; // class StrongParser
|
||||
|
||||
|
@ -12,33 +12,87 @@
|
||||
|
||||
TEST(MADDY_STRONGPARSER, ItReplacesMarkdownWithStrongHTML)
|
||||
{
|
||||
std::string text = "some text **bla** text testing **it** out";
|
||||
std::string expected = "some text <strong>bla</strong> text testing <strong>it</strong> out";
|
||||
struct testIt
|
||||
{
|
||||
std::string text;
|
||||
std::string expected;
|
||||
};
|
||||
|
||||
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 <strong>bla</strong> text testing <strong>it</strong> out"
|
||||
},
|
||||
};
|
||||
|
||||
auto strongParser = std::make_shared<maddy::StrongParser>();
|
||||
|
||||
strongParser->Parse(text);
|
||||
|
||||
ASSERT_EQ(expected, text);
|
||||
for (auto& test : tests)
|
||||
{
|
||||
strongParser->Parse(test.text);
|
||||
ASSERT_EQ(test.expected, test.text);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(MADDY_STRONGPARSER, ItReplacesEmphasizedMarkdownNotWithStrongHTML)
|
||||
{
|
||||
std::string text = "some text *bla* text testing **it** out";
|
||||
std::string expected = "some text *bla* text testing <strong>it</strong> out";
|
||||
struct testIt
|
||||
{
|
||||
std::string text;
|
||||
std::string expected;
|
||||
};
|
||||
|
||||
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 <strong>it</strong> out"
|
||||
},
|
||||
};
|
||||
|
||||
auto strongParser = std::make_shared<maddy::StrongParser>();
|
||||
|
||||
strongParser->Parse(text);
|
||||
|
||||
ASSERT_EQ(expected, text);
|
||||
for (auto& test : tests)
|
||||
{
|
||||
strongParser->Parse(test.text);
|
||||
ASSERT_EQ(test.expected, test.text);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(MADDY_STRONGPARSER, ItDoesNotParseInsideInlineCode)
|
||||
{
|
||||
std::string text = "some text **bla** `/**text**/` testing `**it**` out";
|
||||
std::string expected = "some text **bla** `/**text**/` testing `**it**` out";
|
||||
struct testIt
|
||||
{
|
||||
std::string text;
|
||||
std::string expected;
|
||||
};
|
||||
|
||||
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 <strong>it</strong> out"
|
||||
},
|
||||
};
|
||||
|
||||
auto strongParser = std::make_shared<maddy::StrongParser>();
|
||||
|
||||
strongParser->Parse(text);
|
||||
|
||||
ASSERT_EQ(expected, text);
|
||||
for (auto& test : tests)
|
||||
{
|
||||
strongParser->Parse(test.text);
|
||||
ASSERT_EQ(test.expected, test.text);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user