Tooth/src/Utils.vala

34 lines
1 KiB
Vala
Raw Normal View History

2018-04-25 13:16:57 +00:00
public class Tootle.Utils{
2018-05-04 20:57:31 +00:00
public static void open_url (string url) {
Gtk.show_uri (null, url, Gdk.CURRENT_TIME);
}
public static string escape_html (string content) {
var all_tags = new Regex("<(.|\n)*?>", RegexCompileFlags.CASELESS);
return all_tags.replace(content, -1, 0, "");
}
public static string simplify_html (string content) {
var divided = content
2018-04-25 13:16:57 +00:00
.replace("<br>", "\n")
.replace("</br>", "")
.replace("<br />", "\n")
.replace("<p>", "")
.replace("</p>", "\n\n");
var html_params = new Regex("(class|target|rel)=\"(.|\n)*?\"", RegexCompileFlags.CASELESS);
var simplified = html_params.replace(divided, -1, 0, "");
2018-04-25 13:16:57 +00:00
while (simplified.has_suffix ("\n"))
simplified = simplified.slice (0, simplified.last_index_of ("\n"));
2018-04-25 13:16:57 +00:00
return simplified;
2018-04-25 13:16:57 +00:00
}
2018-05-21 10:40:49 +00:00
public static string escape_entities (string content) {
return content.replace ("&", "&amp;");
}
2018-04-25 13:16:57 +00:00
}