1
0
réplica de https://github.com/quitesimpleorg/qsmaddy.git sincronizado 2024-11-21 23:27:51 +01:00

italicparser: Add first version

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
Este cometimento está contido em:
Patrick José Pereira 2018-10-19 11:43:33 -03:00
ascendente a19845cdb5
cometimento 9b37255346
2 ficheiros modificados com 55 adições e 0 eliminações

50
include/maddy/italicparser.h Ficheiro normal
Ver ficheiro

@ -0,0 +1,50 @@
/*
* This project is licensed under the MIT license. For more information see the
* LICENSE file.
*/
#pragma once
// -----------------------------------------------------------------------------
#include <string>
#include <regex>
#include "maddy/lineparser.h"
// -----------------------------------------------------------------------------
namespace maddy {
// -----------------------------------------------------------------------------
/**
* ItalicParser
*
* @class
*/
class ItalicParser : public LineParser
{
public:
/**
* Parse
*
* From Markdown: `text *text*`
*
* To HTML: `text <i>text</i>`
*
* @method
* @param {std::string&} line The line to interpret
* @return {void}
*/
void
Parse(std::string& line) override
{
std::regex re("(?!.*`.*|.*<code>.*)\\*(?!.*`.*|.*<\\/code>.*)([^\\*]*)\\*(?!.*`.*|.*<\\/code>.*)");
static std::string replacement = "<i>$1</i>";
line = std::regex_replace(line, re, replacement);
}
}; // class ItalicParser
// -----------------------------------------------------------------------------
} // namespace maddy

Ver ficheiro

@ -25,6 +25,7 @@
#include "maddy/emphasizedparser.h" #include "maddy/emphasizedparser.h"
#include "maddy/imageparser.h" #include "maddy/imageparser.h"
#include "maddy/inlinecodeparser.h" #include "maddy/inlinecodeparser.h"
#include "maddy/italicparser.h"
#include "maddy/linkparser.h" #include "maddy/linkparser.h"
#include "maddy/strikethroughparser.h" #include "maddy/strikethroughparser.h"
#include "maddy/strongparser.h" #include "maddy/strongparser.h"
@ -56,6 +57,7 @@ public:
: emphasizedParser(std::make_shared<EmphasizedParser>()) : emphasizedParser(std::make_shared<EmphasizedParser>())
, imageParser(std::make_shared<ImageParser>()) , imageParser(std::make_shared<ImageParser>())
, inlineCodeParser(std::make_shared<InlineCodeParser>()) , inlineCodeParser(std::make_shared<InlineCodeParser>())
, italicParser(std::make_shared<ItalicParser>())
, linkParser(std::make_shared<LinkParser>()) , linkParser(std::make_shared<LinkParser>())
, strikeThroughParser(std::make_shared<StrikeThroughParser>()) , strikeThroughParser(std::make_shared<StrikeThroughParser>())
, strongParser(std::make_shared<StrongParser>()) , strongParser(std::make_shared<StrongParser>())
@ -112,6 +114,7 @@ private:
std::shared_ptr<EmphasizedParser> emphasizedParser; std::shared_ptr<EmphasizedParser> emphasizedParser;
std::shared_ptr<ImageParser> imageParser; std::shared_ptr<ImageParser> imageParser;
std::shared_ptr<InlineCodeParser> inlineCodeParser; std::shared_ptr<InlineCodeParser> inlineCodeParser;
std::shared_ptr<ItalicParser> italicParser;
std::shared_ptr<LinkParser> linkParser; std::shared_ptr<LinkParser> linkParser;
std::shared_ptr<StrikeThroughParser> strikeThroughParser; std::shared_ptr<StrikeThroughParser> strikeThroughParser;
std::shared_ptr<StrongParser> strongParser; std::shared_ptr<StrongParser> strongParser;
@ -131,6 +134,8 @@ private:
this->strikeThroughParser->Parse(line); this->strikeThroughParser->Parse(line);
this->inlineCodeParser->Parse(line); this->inlineCodeParser->Parse(line);
this->italicParser->Parse(line);
} }
std::shared_ptr<BlockParser> std::shared_ptr<BlockParser>