diff --git a/docs/definitions.md b/docs/definitions.md
index f93a380..0b97ae1 100644
--- a/docs/definitions.md
+++ b/docs/definitions.md
@@ -229,10 +229,20 @@ results in
bold text
```
+## italic
+
+```
+*italic text*
+```
+results in
+```html
+italic text
+```
+
## emphasized
```
-*emphasized text*
+_emphasized text_
```
results in
```html
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);
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
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();
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);
+}
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\