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);
|
|
|
|
}
|
|
|
|
|
2018-05-17 17:29:01 +00:00
|
|
|
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>", "")
|
2018-05-17 17:29:01 +00:00
|
|
|
.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
|
|
|
|
2018-05-17 17:29:01 +00:00
|
|
|
while (simplified.has_suffix ("\n"))
|
|
|
|
simplified = simplified.slice (0, simplified.last_index_of ("\n"));
|
2018-04-25 13:16:57 +00:00
|
|
|
|
2018-05-17 17:29:01 +00:00
|
|
|
return simplified;
|
2018-04-25 13:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|