Replace \n in raw text to <br>

https://shonk.social/@Sharkey
This commit is contained in:
blankie 2024-01-04 02:10:16 +11:00
parent 6de34f2d06
commit f37d258a8e
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
2 changed files with 12 additions and 0 deletions

View File

@ -343,6 +343,12 @@ static Element serialize_post(const httplib::Request& req, const std::string& se
blankie::html::HTMLString preprocessed_html = preprocess_html(req, server, post.emojis, post.content); blankie::html::HTMLString preprocessed_html = preprocess_html(req, server, post.emojis, post.content);
// Workaround for https://vt.social/@a1ba@suya.place/110552480243348878#m // Workaround for https://vt.social/@a1ba@suya.place/110552480243348878#m
if (preprocessed_html.str.find("<p>") == std::string::npos) { if (preprocessed_html.str.find("<p>") == std::string::npos) {
size_t offset = 0;
while ((offset = preprocessed_html.str.find('\n', offset)) != std::string::npos) {
preprocessed_html.str.replace(offset, 1, "<br>");
offset += 4;
}
preprocessed_html.str.reserve(preprocessed_html.str.size() + 3 + 4); preprocessed_html.str.reserve(preprocessed_html.str.size() + 3 + 4);
preprocessed_html.str.insert(0, "<p>"); preprocessed_html.str.insert(0, "<p>");
preprocessed_html.str.append("</p>"); preprocessed_html.str.append("</p>");

View File

@ -88,6 +88,12 @@ static inline Element user_header(const httplib::Request& req, const std::string
blankie::html::HTMLString preprocessed_bio = preprocess_html(req, account.server, account.emojis, account.note_html); blankie::html::HTMLString preprocessed_bio = preprocess_html(req, account.server, account.emojis, account.note_html);
// Workaround for https://social.kernel.org/@monsieuricon // Workaround for https://social.kernel.org/@monsieuricon
if (preprocessed_bio.str.find("<p>") == std::string::npos) { if (preprocessed_bio.str.find("<p>") == std::string::npos) {
size_t offset = 0;
while ((offset = preprocessed_bio.str.find('\n', offset)) != std::string::npos) {
preprocessed_bio.str.replace(offset, 1, "<br>");
offset += 4;
}
preprocessed_bio.str.reserve(preprocessed_bio.str.size() + 3 + 4); preprocessed_bio.str.reserve(preprocessed_bio.str.size() + 3 + 4);
preprocessed_bio.str.insert(0, "<p>"); preprocessed_bio.str.insert(0, "<p>");
preprocessed_bio.str.append("</p>"); preprocessed_bio.str.append("</p>");