From 9b37255346c3121d6b5e410c6cb56dc3d3f2efc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Fri, 19 Oct 2018 11:43:33 -0300 Subject: [PATCH 1/6] italicparser: Add first version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- include/maddy/italicparser.h | 50 ++++++++++++++++++++++++++++++++++++ include/maddy/parser.h | 5 ++++ 2 files changed, 55 insertions(+) create mode 100644 include/maddy/italicparser.h diff --git a/include/maddy/italicparser.h b/include/maddy/italicparser.h new file mode 100644 index 0000000..f31b96e --- /dev/null +++ b/include/maddy/italicparser.h @@ -0,0 +1,50 @@ +/* + * This project is licensed under the MIT license. For more information see the + * LICENSE file. + */ +#pragma once + +// ----------------------------------------------------------------------------- + +#include +#include + +#include "maddy/lineparser.h" + +// ----------------------------------------------------------------------------- + +namespace maddy { + +// ----------------------------------------------------------------------------- + +/** + * ItalicParser + * + * @class + */ +class ItalicParser : public LineParser +{ +public: + /** + * Parse + * + * From Markdown: `text *text*` + * + * To HTML: `text text` + * + * @method + * @param {std::string&} line The line to interpret + * @return {void} + */ + void + Parse(std::string& line) override + { + std::regex re("(?!.*`.*|.*.*)\\*(?!.*`.*|.*<\\/code>.*)([^\\*]*)\\*(?!.*`.*|.*<\\/code>.*)"); + static std::string replacement = "$1"; + line = std::regex_replace(line, re, replacement); + } +}; // class ItalicParser + +// ----------------------------------------------------------------------------- + +} // namespace maddy diff --git a/include/maddy/parser.h b/include/maddy/parser.h index b152646..c11401e 100644 --- a/include/maddy/parser.h +++ b/include/maddy/parser.h @@ -25,6 +25,7 @@ #include "maddy/emphasizedparser.h" #include "maddy/imageparser.h" #include "maddy/inlinecodeparser.h" +#include "maddy/italicparser.h" #include "maddy/linkparser.h" #include "maddy/strikethroughparser.h" #include "maddy/strongparser.h" @@ -56,6 +57,7 @@ public: : emphasizedParser(std::make_shared()) , imageParser(std::make_shared()) , inlineCodeParser(std::make_shared()) + , italicParser(std::make_shared()) , linkParser(std::make_shared()) , strikeThroughParser(std::make_shared()) , strongParser(std::make_shared()) @@ -112,6 +114,7 @@ private: std::shared_ptr emphasizedParser; std::shared_ptr imageParser; std::shared_ptr inlineCodeParser; + std::shared_ptr italicParser; std::shared_ptr linkParser; std::shared_ptr strikeThroughParser; std::shared_ptr strongParser; @@ -131,6 +134,8 @@ private: this->strikeThroughParser->Parse(line); this->inlineCodeParser->Parse(line); + + this->italicParser->Parse(line); } std::shared_ptr From e8ba8f661af7fe966ac105f6f37358a7a0a22ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Fri, 19 Oct 2018 11:50:04 -0300 Subject: [PATCH 2/6] test_maddy_italicparser: Add tests for the italic parser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- tests/maddy/test_maddy_italicparser.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/maddy/test_maddy_italicparser.cpp diff --git a/tests/maddy/test_maddy_italicparser.cpp b/tests/maddy/test_maddy_italicparser.cpp new file mode 100644 index 0000000..c87f266 --- /dev/null +++ b/tests/maddy/test_maddy_italicparser.cpp @@ -0,0 +1,23 @@ +/* + * This project is licensed under the MIT license. For more information see the + * LICENSE file. + */ +#include + +#include "gmock/gmock.h" + +#include "maddy/italicparser.h" + +// ----------------------------------------------------------------------------- + +TEST(MADDY_ITALICPARSER, ItReplacesMarkdownWithItalicHTML) +{ + + std::string text = "some text *bla* text testing *it* out"; + std::string expected = "some text bla text testing it out"; + auto italicParser = std::make_shared(); + + italicParser->Parse(text); + + ASSERT_EQ(text, expected); +} From ee42f7eae925aaa5ecd750e5e253b40e28089d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Thu, 25 Oct 2018 11:11:24 -0300 Subject: [PATCH 3/6] emphasizedparser: Move from *this* to _this_ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- include/maddy/emphasizedparser.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/maddy/emphasizedparser.h b/include/maddy/emphasizedparser.h index 65cf11b..56d43dc 100644 --- a/include/maddy/emphasizedparser.h +++ b/include/maddy/emphasizedparser.h @@ -30,7 +30,7 @@ public: /** * Parse * - * From Markdown: `text *text*` + * From Markdown: `text _text_` * * To HTML: `text text` * @@ -41,7 +41,7 @@ public: void Parse(std::string& line) override { - static std::regex re("(?!.*`.*|.*.*)\\*(?!.*`.*|.*<\\/code>.*)([^\\*]*)\\*(?!.*`.*|.*<\\/code>.*)"); + static std::regex re("(?!.*`.*|.*.*)\\_(?!.*`.*|.*<\\/code>.*)([^\\_]*)\\_(?!.*`.*|.*<\\/code>.*)"); static std::string replacement = "$1"; line = std::regex_replace(line, re, replacement); From 6e7aec7947ca817e3f6ffdaaefe139216a5e7445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Thu, 25 Oct 2018 11:07:24 -0300 Subject: [PATCH 4/6] test_maddy_emphasizedparser: Update tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- tests/maddy/test_maddy_emphasizedparser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/maddy/test_maddy_emphasizedparser.cpp b/tests/maddy/test_maddy_emphasizedparser.cpp index c200313..c4cd56c 100644 --- a/tests/maddy/test_maddy_emphasizedparser.cpp +++ b/tests/maddy/test_maddy_emphasizedparser.cpp @@ -12,7 +12,7 @@ TEST(MADDY_EMPHASIZEDPARSER, ItReplacesMarkdownWithEmphasizedHTML) { - 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 it out"; auto emphasizedParser = std::make_shared(); @@ -23,7 +23,7 @@ TEST(MADDY_EMPHASIZEDPARSER, ItReplacesMarkdownWithEmphasizedHTML) 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 it out"; auto emphasizedParser = std::make_shared(); From 2562d780b85335fa20d4639c983ab48e010a331b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Thu, 25 Oct 2018 11:08:38 -0300 Subject: [PATCH 5/6] test_maddy_parser: Update main test with emphasized tag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- tests/maddy/test_maddy_parser.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/maddy/test_maddy_parser.h b/tests/maddy/test_maddy_parser.h index 00bbc1c..0d7898a 100644 --- a/tests/maddy/test_maddy_parser.h +++ b/tests/maddy/test_maddy_parser.h @@ -13,7 +13,7 @@ it's that simple.\n\ \n\ * an unordered list\n\ * with some **hierarchy**\n\ - 1. and an *ordered*\n\ + 1. and an _ordered_\n\ * list\n\ * directly\n\ * inside\n\ From eae3b270c03c345515542c0854d871dbe3b8d4a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Thu, 25 Oct 2018 10:41:10 -0300 Subject: [PATCH 6/6] docs: Update italic and emphasized documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- docs/definitions.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/definitions.md b/docs/definitions.md index a17e7bd..931452c 100644 --- a/docs/definitions.md +++ b/docs/definitions.md @@ -227,10 +227,20 @@ results in bold text ``` +## italic + +``` +*italic text* +``` +results in +```html +italic text +``` + ## emphasized ``` -*emphasized text* +_emphasized text_ ``` results in ```html