diff --git a/AUTHORS b/AUTHORS index de388e1..c29b373 100644 --- a/AUTHORS +++ b/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) diff --git a/docs/definitions.md b/docs/definitions.md index a17e7bd..f93a380 100644 --- a/docs/definitions.md +++ b/docs/definitions.md @@ -221,10 +221,12 @@ results in ``` **bold text** +__bold text__ ``` results in ```html bold text +bold text ``` ## emphasized diff --git a/include/maddy/strongparser.h b/include/maddy/strongparser.h index cda6d21..c2dc441 100644 --- a/include/maddy/strongparser.h +++ b/include/maddy/strongparser.h @@ -30,9 +30,9 @@ public: /** * Parse * - * From Markdown: `text **text**` + * From Markdown: `text **text** __text__` * - * To HTML: `text text` + * To HTML: `text text text` * * @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>.*)"); + static std::vector res + { + std::regex{"(?!.*`.*|.*.*)\\*\\*(?!.*`.*|.*<\\/code>.*)([^\\*\\*]*)\\*\\*(?!.*`.*|.*<\\/code>.*)"}, + std::regex{"(?!.*`.*|.*.*)\\_\\_(?!.*`.*|.*<\\/code>.*)([^\\_\\_]*)\\_\\_(?!.*`.*|.*<\\/code>.*)"} + }; static std::string replacement = "$1"; - - line = std::regex_replace(line, re, replacement); + for (const auto& re : res) + { + line = std::regex_replace(line, re, replacement); + } } }; // class StrongParser diff --git a/tests/maddy/test_maddy_strongparser.cpp b/tests/maddy/test_maddy_strongparser.cpp index ad70762..e054aa7 100644 --- a/tests/maddy/test_maddy_strongparser.cpp +++ b/tests/maddy/test_maddy_strongparser.cpp @@ -12,33 +12,87 @@ TEST(MADDY_STRONGPARSER, ItReplacesMarkdownWithStrongHTML) { - 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 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" + }, + }; + auto strongParser = std::make_shared(); - 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 it out"; + struct testIt + { + std::string text; + std::string expected; + }; + + std::vector 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" + }, + }; + auto strongParser = std::make_shared(); - 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 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" + }, + }; + auto strongParser = std::make_shared(); - strongParser->Parse(text); - - ASSERT_EQ(expected, text); + for (auto& test : tests) + { + strongParser->Parse(test.text); + ASSERT_EQ(test.expected, test.text); + } }