parser: Consume superfluous newlines, add [br] and [p]
Šī revīzija ir iekļauta:
vecāks
61e84a98c7
revīzija
2ebdbd0b6d
24
parser.cpp
24
parser.cpp
@ -175,14 +175,22 @@ std::string Parser::parse(const PageDao &pagedao, UrlProvider &provider, const s
|
||||
std::string result;
|
||||
// we don't care about commands, but we nevertheless replace them with empty strings
|
||||
std::regex tagfinder(
|
||||
R"(\[(b|i|u|s|li||ul|ol|code|blockquote|img|link|wikilink|h\d|cmd:visible|cmd:listed|cmd:feedlisted|cmd:rename|cmd:redirect|cmd:pagetitle|cmd:allowinclude|cmd:permissions|cmd:parentpage|content|category|dynamic:postlist|dynamic:includepage|dynamic:getvar|dynamic:setvar)*?\]((\s|\S)*?)\[/\1])");
|
||||
R"(\[(b|i|u|s|li|p|br|ul|ol|code|blockquote|img|link|wikilink|h\d|cmd:visible|cmd:listed|cmd:feedlisted|cmd:rename|cmd:redirect|cmd:pagetitle|cmd:allowinclude|cmd:permissions|cmd:parentpage|content|category|dynamic:postlist|dynamic:includepage|dynamic:getvar|dynamic:setvar)*?\]((\s|\S)*?)\[/\1](\r\n)*)");
|
||||
|
||||
const std::string justreplace[] = {"b", "i", "u", "p", "br", "ul", "li", "ol"};
|
||||
|
||||
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", "s"};
|
||||
|
||||
std::string newlines = match.str(4);
|
||||
if(newlines == "\r\n")
|
||||
{
|
||||
newlines = "<br>";
|
||||
}
|
||||
if(tag != "code" && tag != "blockquote")
|
||||
{
|
||||
content = parse(pagedao, provider, content, callback);
|
||||
@ -194,13 +202,17 @@ std::string Parser::parse(const PageDao &pagedao, UrlProvider &provider, const s
|
||||
}
|
||||
if(std::find(std::begin(justreplace), std::end(justreplace), tag) != std::end(justreplace))
|
||||
{
|
||||
return "<" + tag + ">" + content + "</" + tag + ">";
|
||||
if(tag == "p" || tag == "br")
|
||||
{
|
||||
newlines = "";
|
||||
}
|
||||
return "<" + tag + ">" + content + "</" + tag + ">" + newlines;
|
||||
}
|
||||
if(tag == "link" || tag == "wikilink")
|
||||
{
|
||||
return this->processLink(
|
||||
pagedao, provider,
|
||||
match); // TODO: recreate this so we don't check inside the function stuff again
|
||||
return this->processLink(pagedao, provider,
|
||||
match) +
|
||||
newlines; // TODO: recreate this so we don't check inside the function stuff again
|
||||
}
|
||||
if(tag == "img")
|
||||
{
|
||||
|
Notiek ielāde…
Atsaukties uz šo jaunā problēmā
Block a user