mirror of https://github.com/adamdruppe/arsd.git
wrong newline handling in string -> Html
This commit is contained in:
parent
6d25e0fe86
commit
9451c4909f
23
web.d
23
web.d
|
@ -1519,7 +1519,7 @@ string toHtml(T)(T a) {
|
||||||
else static if(is(T == Html))
|
else static if(is(T == Html))
|
||||||
ret = a.source;
|
ret = a.source;
|
||||||
else
|
else
|
||||||
ret = htmlEntitiesEncode(std.array.replace(to!string(a), "\n", "<br />\n"));
|
ret = std.array.replace(htmlEntitiesEncode(to!string(a)), "\n", "<br />\n");
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -2325,8 +2325,10 @@ void setLoginCookie(Cgi cgi, string name, string value) {
|
||||||
cgi.setCookie(name, value, 0, "/", null, true);
|
cgi.setCookie(name, value, 0, "/", null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
string htmlTemplateWithData(in string text, in string[string] vars) {
|
// this thing sucks in so many ways. it's kinda useful tho
|
||||||
assert(text !is null);
|
string htmlTemplateWithData(in string text, in string[string] vars, bool useHtml = true) {
|
||||||
|
if(text is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
string newText = text;
|
string newText = text;
|
||||||
|
|
||||||
|
@ -2334,12 +2336,25 @@ string htmlTemplateWithData(in string text, in string[string] vars) {
|
||||||
foreach(k, v; vars) {
|
foreach(k, v; vars) {
|
||||||
//assert(k !is null);
|
//assert(k !is null);
|
||||||
//assert(v !is null);
|
//assert(v !is null);
|
||||||
newText = newText.replace("{$" ~ k ~ "}", htmlEntitiesEncode(v).replace("\n", "<br />"));
|
string replacement = useHtml ? htmlEntitiesEncode(v).replace("\n", "<br />") : v;
|
||||||
|
newText = newText.replace("{$" ~ k ~ "}", replacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
return newText;
|
return newText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void applyTemplateToElement(Element e, in string[string] vars) {
|
||||||
|
foreach(ele; e.tree) {
|
||||||
|
foreach(k, v; ele.attributes)
|
||||||
|
ele.attributes[k] = htmlTemplateWithData(v, vars, false);
|
||||||
|
auto tc = cast(TextNode) ele;
|
||||||
|
if(tc !is null) {
|
||||||
|
// FIXME: this should arguably be null
|
||||||
|
tc.contents = htmlTemplateWithData(tc.contents, vars, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
string htmlTemplate(string filename, string[string] vars) {
|
string htmlTemplate(string filename, string[string] vars) {
|
||||||
return htmlTemplateWithData(readText(filename), vars);
|
return htmlTemplateWithData(readText(filename), vars);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue