1
0
镜像自地址 https://github.com/quitesimpleorg/qsmaddy.git 已同步 2024-11-21 15:17:52 +01:00

italicparser: Add first version

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
这个提交包含在:
Patrick José Pereira 2018-10-19 11:43:33 -03:00
父节点 a19845cdb5
当前提交 9b37255346
共有 2 个文件被更改,包括 55 次插入0 次删除

查看文件

@ -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

查看文件

@ -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<EmphasizedParser>())
, imageParser(std::make_shared<ImageParser>())
, inlineCodeParser(std::make_shared<InlineCodeParser>())
, italicParser(std::make_shared<ItalicParser>())
, linkParser(std::make_shared<LinkParser>())
, strikeThroughParser(std::make_shared<StrikeThroughParser>())
, strongParser(std::make_shared<StrongParser>())
@ -112,6 +114,7 @@ private:
std::shared_ptr<EmphasizedParser> emphasizedParser;
std::shared_ptr<ImageParser> imageParser;
std::shared_ptr<InlineCodeParser> inlineCodeParser;
std::shared_ptr<ItalicParser> italicParser;
std::shared_ptr<LinkParser> linkParser;
std::shared_ptr<StrikeThroughParser> strikeThroughParser;
std::shared_ptr<StrongParser> strongParser;
@ -131,6 +134,8 @@ private:
this->strikeThroughParser->Parse(line);
this->inlineCodeParser->Parse(line);
this->italicParser->Parse(line);
}
std::shared_ptr<BlockParser>