feature/markdown #23
@ -1,8 +1,36 @@
|
|||||||
#include "parsermarkdown.h"
|
#include "parsermarkdown.h"
|
||||||
|
#include "logger.h"
|
||||||
|
#include "htmllink.h"
|
||||||
|
|
||||||
|
std::string ParserMarkdown::processLink(const PageDao &pageDao, UrlProvider &urlProvider, std::smatch &match) const
|
||||||
|
{
|
||||||
|
std::string inner = match.str(1);
|
||||||
|
std::string link = match.str(2);
|
||||||
|
HtmlLink htmllink;
|
||||||
|
htmllink.href = link;
|
||||||
|
htmllink.innervalue = inner;
|
||||||
|
|
||||||
|
if(link.find("http://") == 0 || link.find("https://") == 0)
|
||||||
|
{
|
||||||
|
return htmllink.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pageDao.exists(link))
|
||||||
|
{
|
||||||
|
htmllink.cssclass = "exists";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
htmllink.cssclass = "notexists";
|
||||||
|
}
|
||||||
|
|
||||||
|
htmllink.href = urlProvider.page(htmllink.href);
|
||||||
|
|
||||||
|
return htmllink.render();
|
||||||
|
}
|
||||||
|
|
||||||
ParserMarkdown::ParserMarkdown()
|
ParserMarkdown::ParserMarkdown()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Headline> ParserMarkdown::extractHeadlines(std::string content) const
|
std::vector<Headline> ParserMarkdown::extractHeadlines(std::string content) const
|
||||||
@ -21,6 +49,13 @@ std::string ParserMarkdown::parse(const PageDao &pagedao, UrlProvider &provider,
|
|||||||
{
|
{
|
||||||
std::shared_ptr<maddy::ParserConfig> config = std::make_shared<maddy::ParserConfig>();
|
std::shared_ptr<maddy::ParserConfig> config = std::make_shared<maddy::ParserConfig>();
|
||||||
auto maddy = std::make_shared<maddy::Parser>(config);
|
auto maddy = std::make_shared<maddy::Parser>(config);
|
||||||
|
|
||||||
|
auto linkParser = std::make_shared<maddy::LinkParser>();
|
||||||
|
linkParser->setCallback([&](std::smatch &match) { return processLink(pagedao, provider, match); });
|
||||||
|
maddy->setLinkParser(linkParser);
|
||||||
|
// TODO: hack because the parser breaks if there is an \r
|
||||||
|
content = utils::strreplace(content, "\r", "");
|
||||||
std::stringstream s{content};
|
std::stringstream s{content};
|
||||||
return maddy->Parse(s);
|
std::string result = maddy->Parse(s);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,11 @@
|
|||||||
#include "maddy/parser.h"
|
#include "maddy/parser.h"
|
||||||
class ParserMarkdown : public Parser
|
class ParserMarkdown : public Parser
|
||||||
{
|
{
|
||||||
public:
|
private:
|
||||||
ParserMarkdown();
|
std::string processLink(const PageDao &pageDao, UrlProvider &urlProvider, std::smatch &match) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
ParserMarkdown();
|
||||||
std::vector<Headline> extractHeadlines(std::string content) const;
|
std::vector<Headline> extractHeadlines(std::string content) const;
|
||||||
std::string parse(const PageDao &pagedao, UrlProvider &provider, std::string content) const;
|
std::string parse(const PageDao &pagedao, UrlProvider &provider, std::string content) const;
|
||||||
};
|
};
|
||||||
|
Laden…
Verwijs in nieuw issue
Block a user