Parser: Add code,blockquote and begin img tag
Cette révision appartient à :
Parent
b0c715c4ea
révision
0325cdf936
33
parser.cpp
33
parser.cpp
@ -117,20 +117,45 @@ std::string Parser::processLink(const PageDao &pageDao, UrlProvider &urlProvider
|
||||
return htmllink.render();
|
||||
}
|
||||
|
||||
std::string Parser::processImage(std::smatch &match) const
|
||||
{
|
||||
std::string tag = match.str(1);
|
||||
std::string inside = match.str(2);
|
||||
std::vector<std::string> splitted = utils::split(inside, '|');
|
||||
std::string width;
|
||||
std::string height;
|
||||
std::string src;
|
||||
if(splitted.size() == 3)
|
||||
{
|
||||
width = splitted[0];
|
||||
height = splitted[1];
|
||||
src = splitted[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
src = splitted[0];
|
||||
}
|
||||
if(!width.empty() && !height.empty())
|
||||
{
|
||||
return "<img src=\"" + src + "\" width=\"" + width + "\" height=\"" + height + "\"/>";
|
||||
}
|
||||
return "<img src=\"" + src + "\"/>";
|
||||
}
|
||||
|
||||
std::string Parser::parse(const PageDao &pagedao, UrlProvider &provider, const std::string &content,
|
||||
const std::function<std::string(std::string_view, std::string_view)> &callback) const
|
||||
{
|
||||
std::string result;
|
||||
// we don't care about commands, but we nevertheless replace them with empty strings
|
||||
std::regex tagfinder(
|
||||
R"(\[(b|i|u|li||ul|ol|link|wikilink|h\d|cmd:visible|cmd:rename|cmd:redirect|cmd:pagetitle|category|dynamic:postlist|dynamic:includepage|dynamic:getvar|dynamic:setvar)*?\]((\s|\S)*?)\[/\1])");
|
||||
R"(\[(b|i|u|li||ul|ol|code|blockquote|img|link|wikilink|h\d|cmd:visible|cmd:rename|cmd:redirect|cmd:pagetitle|category|dynamic:postlist|dynamic:includepage|dynamic:getvar|dynamic:setvar)*?\]((\s|\S)*?)\[/\1])");
|
||||
result = utils::regex_callback_replacer(
|
||||
tagfinder, content,
|
||||
[&](std::smatch &match)
|
||||
{
|
||||
std::string tag = match.str(1);
|
||||
std::string content = match.str(2);
|
||||
std::string justreplace[] = {"b", "i", "u", "ul", "li", "ol"};
|
||||
std::string justreplace[] = {"b", "i", "u", "ul", "li", "ol", "code", "blockquote"};
|
||||
content = parse(pagedao, provider, content, callback);
|
||||
if(std::find(std::begin(justreplace), std::end(justreplace), tag) != std::end(justreplace))
|
||||
{
|
||||
@ -142,6 +167,10 @@ std::string Parser::parse(const PageDao &pagedao, UrlProvider &provider, const s
|
||||
pagedao, provider,
|
||||
match); // TODO: recreate this so we don't check inside the function stuff again
|
||||
}
|
||||
if(tag == "img")
|
||||
{
|
||||
return this->processImage(match);
|
||||
}
|
||||
if(tag[0] == 'h')
|
||||
{
|
||||
return "<" + tag + " id='" + content + "'>" + content + "</" + tag + ">";
|
||||
|
1
parser.h
1
parser.h
@ -6,6 +6,7 @@ class Parser : public IParser
|
||||
{
|
||||
private:
|
||||
std::string processLink(const PageDao &pageDao, UrlProvider &urlProvider, std::smatch &match) const;
|
||||
std::string processImage(std::smatch &match) const;
|
||||
|
||||
public:
|
||||
std::string extractCommand(std::string cmdname, const std::string &content) const;
|
||||
|
Chargement…
Référencer dans un nouveau ticket
Block a user