define html2text () {
variable art, f, fname, line, qp;
art = "";
f = popen ("mktemp -q /tmp/slrn-html2text.XXXXXX | tr -d '\n'", "r");
if (f == NULL) return;
if (-1 == fgets (&fname, f)) return;
pclose (f);
f = popen ("/usr/bin/html2markdown --reference-links - >"+fname, "w");
if (f == NULL) {
error ("Unable to filter article to "+fname);
return;
}
variable article_string, header_end, article_headers, article_body;
article_string=article_as_string();
header_end=string_match(article_string, "\n\n");
article_headers=substr(article_string, 1, header_end);
article_body=substr(article_string, header_end, -1);
() = fputs (article_body, f);
() = pclose (f);
f = fopen (fname, "r");
if (f == NULL) {
error (fname+" could not be opened.");
return;
}
while (-1 != fgets (&line, f)) {
art = art + line;
}
fclose (f);
if (0 != remove(fname)) error ("Unable to remove "+fname);
replace_article (strjoin([article_headers, art], "\n"));
}
define register_html2text () {
if (1 == register_hook("read_article_hook", "html2text")) {
error("html2text filtering activated");
}
else {
error("html2text filtering NOT activated");
}
}
define unregister_html2text () {
if (1 == unregister_hook("read_article_hook", "html2text")) {
error("html2text filtering deactivated");
}
else {
error("html2text filtering NOT deactivated");
}
}
% filtering is enabled by default:
register_hook("read_article_hook", "html2text");