tootle-linux-client/src/Html.vala

31 lines
984 B
Vala
Raw Normal View History

public class Tootle.Html {
2018-06-06 16:19:11 +02:00
public static string remove_tags (string content) {
2020-05-29 14:19:35 +02:00
var all_tags = new Regex ("<(.|\n)*?>", RegexCompileFlags.CASELESS);
return GLib.Markup.escape_text (all_tags.replace (content, -1, 0, ""));
}
2020-05-29 14:19:35 +02:00
public static string simplify (string str) {
var divided = str
.replace("<br>", "\n")
.replace("</br>", "")
.replace("<br />", "\n")
.replace("<p>", "")
.replace("</p>", "\n\n");
2020-05-29 14:19:35 +02:00
var html_params = new Regex ("(class|target|rel)=\"(.|\n)*?\"", RegexCompileFlags.CASELESS);
var simplified = html_params.replace (divided, -1, 0, "");
while (simplified.has_suffix ("\n"))
simplified = simplified.slice (0, simplified.last_index_of ("\n"));
2020-06-29 23:43:45 +02:00
return simplified;
}
2020-05-29 14:19:35 +02:00
public static string uri_encode (string str) {
2020-06-29 23:43:45 +02:00
var restored = Widgets.RichLabel.restore_entities (str);
2020-05-29 14:19:35 +02:00
return Soup.URI.encode (restored, ";&+");
}
}