Compare commits
2 Commits
ca0c8a94fb
...
b2a7ea4031
Author | SHA1 | Date | |
---|---|---|---|
b2a7ea4031 | |||
1d5bf80710 |
@ -167,6 +167,7 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename,
|
||||
}
|
||||
}
|
||||
std::string revisionstr = std::to_string(revision->revision);
|
||||
std::string customtitle = parser.extractCommand("pagetitle", revision->content);
|
||||
page.setVar("content", parsedcontent);
|
||||
page.setVar("index", indexcontent);
|
||||
page.setVar("editedby", revision->author);
|
||||
@ -174,6 +175,10 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename,
|
||||
page.setVar("historyurl", this->urlProvider->pageHistory(pagename));
|
||||
page.setVar("revision", revisionstr);
|
||||
setPageVars(page, pagename);
|
||||
if(!customtitle.empty())
|
||||
{
|
||||
page.setVar("title", createPageTitle(customtitle));
|
||||
}
|
||||
std::string body = page.render();
|
||||
if(revisionid == 0 && !this->userSession->loggedIn)
|
||||
{
|
||||
|
@ -8,10 +8,10 @@
|
||||
class IParser
|
||||
{
|
||||
public:
|
||||
virtual std::string extractCommand(std::string cmdname, std::string content) const = 0;
|
||||
virtual std::vector<Headline> extractHeadlines(std::string content) const = 0;
|
||||
virtual std::string parse(const PageDao &pagedao, UrlProvider &provider, std::string content) const = 0;
|
||||
virtual std::vector<std::string> extractCategories(std::string content) const = 0;
|
||||
virtual std::string extractCommand(std::string cmdname, const std::string &content) const = 0;
|
||||
virtual std::vector<Headline> extractHeadlines(const std::string &content) const = 0;
|
||||
virtual std::string parse(const PageDao &pagedao, UrlProvider &provider, const std::string &content) const = 0;
|
||||
virtual std::vector<std::string> extractCategories(const std::string &content) const = 0;
|
||||
|
||||
virtual ~IParser(){};
|
||||
};
|
||||
|
19
parser.cpp
19
parser.cpp
@ -27,7 +27,7 @@ SOFTWARE.
|
||||
#include "parser.h"
|
||||
#include "utils.h"
|
||||
#include "htmllink.h"
|
||||
std::vector<Headline> Parser::extractHeadlines(std::string content) const
|
||||
std::vector<Headline> Parser::extractHeadlines(const std::string &content) const
|
||||
{
|
||||
std::vector<Headline> result;
|
||||
std::string reg = R"(\[h(1|2|3)\](.*?)\[/h\1\])";
|
||||
@ -46,7 +46,7 @@ std::vector<Headline> Parser::extractHeadlines(std::string content) const
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> Parser::extractCategories(std::string content) const
|
||||
std::vector<std::string> Parser::extractCategories(const std::string &content) const
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
std::string reg = R"(\[category\](.*?)\[/category\])";
|
||||
@ -62,7 +62,7 @@ std::vector<std::string> Parser::extractCategories(std::string content) const
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string Parser::extractCommand(std::string cmdname, std::string content) const
|
||||
std::string Parser::extractCommand(std::string cmdname, const std::string &content) const
|
||||
{
|
||||
std::string cmd = "[cmd:" + cmdname + "]";
|
||||
std::string cmdend = "[/cmd:" + cmdname + "]";
|
||||
@ -116,12 +116,16 @@ std::string Parser::processLink(const PageDao &pageDao, UrlProvider &urlProvider
|
||||
return htmllink.render();
|
||||
}
|
||||
|
||||
std::string Parser::parse(const PageDao &pagedao, UrlProvider &provider, std::string content) const
|
||||
std::string Parser::parse(const PageDao &pagedao, UrlProvider &provider, const std::string &content) 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:rename|cmd:redirect|category)*?\]((\s|\S)*?)\[/\1])");
|
||||
result = utils::regex_callback_replacer(tagfinder, content, [&](std::smatch &match) {
|
||||
std::regex tagfinder(
|
||||
R"(\[(b|i|u|li||ul|ol|link|wikilink|h\d|cmd:rename|cmd:redirect|cmd:pagetitle|category)*?\]((\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"};
|
||||
@ -132,7 +136,8 @@ std::string Parser::parse(const PageDao &pagedao, UrlProvider &provider, std::st
|
||||
}
|
||||
if(tag == "link" || tag == "wikilink")
|
||||
{
|
||||
return this->processLink(pagedao, provider,
|
||||
return this->processLink(
|
||||
pagedao, provider,
|
||||
match); // TODO: recreate this so we don't check inside the function stuff again
|
||||
}
|
||||
if(tag[0] == 'h')
|
||||
|
8
parser.h
8
parser.h
@ -8,10 +8,10 @@ class Parser : public IParser
|
||||
std::string processLink(const PageDao &pageDao, UrlProvider &urlProvider, std::smatch &match) const;
|
||||
|
||||
public:
|
||||
std::string extractCommand(std::string cmdname, std::string content) const;
|
||||
std::vector<Headline> extractHeadlines(std::string content) const override;
|
||||
std::vector<std::string> extractCategories(std::string content) const override;
|
||||
std::string parse(const PageDao &pagedao, UrlProvider &provider, std::string content) const override;
|
||||
std::string extractCommand(std::string cmdname, const std::string &content) const;
|
||||
std::vector<Headline> extractHeadlines(const std::string &content) const override;
|
||||
std::vector<std::string> extractCategories(const std::string &content) const override;
|
||||
std::string parse(const PageDao &pagedao, UrlProvider &provider, const std::string &content) const override;
|
||||
using IParser::IParser;
|
||||
~Parser(){};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user