Commit 3d918355 authored by Link Mauve's avatar Link Mauve Committed by louiz’

Convert \n to <br/> in xhtml body

fix #2539
parent 2d5e2fdc
...@@ -77,6 +77,13 @@ Xmpp::body irc_format_to_xhtmlim(const std::string& s) ...@@ -77,6 +77,13 @@ Xmpp::body irc_format_to_xhtmlim(const std::string& s)
if (s[pos_end] == IRC_FORMAT_BOLD_CHAR) if (s[pos_end] == IRC_FORMAT_BOLD_CHAR)
styles.strong = !styles.strong; styles.strong = !styles.strong;
else if (s[pos_end] == IRC_FORMAT_NEWLINE_CHAR)
{
XmlNode* br_node = new XmlNode("br");
br_node->close();
current_node->add_child(br_node);
cleaned += '\n';
}
else if (s[pos_end] == IRC_FORMAT_UNDERLINE_CHAR) else if (s[pos_end] == IRC_FORMAT_UNDERLINE_CHAR)
styles.underline = !styles.underline; styles.underline = !styles.underline;
else if (s[pos_end] == IRC_FORMAT_ITALIC_CHAR) else if (s[pos_end] == IRC_FORMAT_ITALIC_CHAR)
......
...@@ -28,6 +28,7 @@ namespace Xmpp ...@@ -28,6 +28,7 @@ namespace Xmpp
#define IRC_FORMAT_REVERSE2_CHAR '\x16' // wat #define IRC_FORMAT_REVERSE2_CHAR '\x16' // wat
#define IRC_FORMAT_ITALIC_CHAR '\x1D' // done #define IRC_FORMAT_ITALIC_CHAR '\x1D' // done
#define IRC_FORMAT_UNDERLINE_CHAR '\x1F' // done #define IRC_FORMAT_UNDERLINE_CHAR '\x1F' // done
#define IRC_FORMAT_NEWLINE_CHAR '\n' // done
static const char irc_format_char[] = { static const char irc_format_char[] = {
IRC_FORMAT_BOLD_CHAR, IRC_FORMAT_BOLD_CHAR,
...@@ -38,6 +39,7 @@ static const char irc_format_char[] = { ...@@ -38,6 +39,7 @@ static const char irc_format_char[] = {
IRC_FORMAT_REVERSE2_CHAR, IRC_FORMAT_REVERSE2_CHAR,
IRC_FORMAT_ITALIC_CHAR, IRC_FORMAT_ITALIC_CHAR,
IRC_FORMAT_UNDERLINE_CHAR, IRC_FORMAT_UNDERLINE_CHAR,
IRC_FORMAT_NEWLINE_CHAR,
'\x00' '\x00'
}; };
......
...@@ -258,6 +258,10 @@ int main() ...@@ -258,6 +258,10 @@ int main()
assert(cleaned_up == "0e46ab by Pierre Dindon [0|1|0] http://example.net/Ojrh4P media: avoid pop-in effect when loading thumbnails by specifying an explicit size"); assert(cleaned_up == "0e46ab by Pierre Dindon [0|1|0] http://example.net/Ojrh4P media: avoid pop-in effect when loading thumbnails by specifying an explicit size");
assert(xhtml->to_string() == "<body xmlns='http://www.w3.org/1999/xhtml'>0e46ab by <span style='color:green;'>Pierre Dindon</span> [<span style='color:lightgreen;'>0</span>|<span style='color:lightgreen;'>1</span>|<span style='color:indianred;'>0</span>] <span style='text-decoration:underline;'/><span style='text-decoration:underline;color:blue;'>http://example.net/Ojrh4P</span><span style='text-decoration:underline;'/> media: avoid pop-in effect when loading thumbnails by specifying an explicit size</body>"); assert(xhtml->to_string() == "<body xmlns='http://www.w3.org/1999/xhtml'>0e46ab by <span style='color:green;'>Pierre Dindon</span> [<span style='color:lightgreen;'>0</span>|<span style='color:lightgreen;'>1</span>|<span style='color:indianred;'>0</span>] <span style='text-decoration:underline;'/><span style='text-decoration:underline;color:blue;'>http://example.net/Ojrh4P</span><span style='text-decoration:underline;'/> media: avoid pop-in effect when loading thumbnails by specifying an explicit size</body>");
std::tie(cleaned_up, xhtml) = irc_format_to_xhtmlim("test\ncoucou");
assert(cleaned_up == "test\ncoucou");
assert(xhtml->to_string() == "<body xmlns='http://www.w3.org/1999/xhtml'>test<br/>coucou</body>");
/** /**
* JID parsing * JID parsing
*/ */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment