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