diff --git a/parser.cpp b/parser.cpp index b37647a..cadf410 100644 --- a/parser.cpp +++ b/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 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 ""; + } + return ""; +} + std::string Parser::parse(const PageDao &pagedao, UrlProvider &provider, const std::string &content, const std::function &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 + ""; diff --git a/parser.h b/parser.h index 863e034..eca8085 100644 --- a/parser.h +++ b/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;