Implement IRC format to xhtml-im conversion

The generated XML is very verbose because each IRC formatting tag makes us
close a <span/> element and reopen it with the new style applied.  However,
this works quite well and is easy to implement.
This commit is contained in:
Florent Le Coz
2013-11-28 01:18:26 +01:00
parent 31e18e49b6
commit e6f20d3c0f
8 changed files with 275 additions and 47 deletions
+25
View File
@@ -84,6 +84,31 @@ int main()
assert(xml_escape(unescaped) == "&apos;coucou&apos;&lt;cc&gt;/&amp;&quot;gaga&quot;");
assert(xml_unescape(xml_escape(unescaped)) == unescaped);
/**
* Colors conversion
*/
std::unique_ptr<XmlNode> xhtml;
std::string cleaned_up;
std::tie(cleaned_up, xhtml) =
irc_format_to_xhtmlim("normalboldunder-and-boldbold normal"
"5red,5default-on-red10,2cyan-on-blue");
assert(xhtml);
assert(xhtml->to_string() == "<body xmlns='http://www.w3.org/1999/xhtml'>normal<span style='font-weight:bold;'>bold</span><span style='font-weight:bold;text-decoration:underline;'>under-and-bold</span><span style='font-weight:bold;'>bold</span> normal<span style='color:red;'>red</span><span style='background-color:red;'>default-on-red</span><span style='color:cyan;background-color:blue;'>cyan-on-blue</span></body>");
assert(cleaned_up == "normalboldunder-and-boldbold normalreddefault-on-redcyan-on-blue");
std::tie(cleaned_up, xhtml) = irc_format_to_xhtmlim("normal");
assert(!xhtml && cleaned_up == "normal");
std::tie(cleaned_up, xhtml) = irc_format_to_xhtmlim("");
assert(xhtml && !xhtml->has_children() && cleaned_up.empty());
std::tie(cleaned_up, xhtml) = irc_format_to_xhtmlim(",a");
assert(xhtml && !xhtml->has_children() && cleaned_up == "a");
std::tie(cleaned_up, xhtml) = irc_format_to_xhtmlim(",");
assert(xhtml && !xhtml->has_children() && cleaned_up.empty());
/**
* JID parsing
*/