Fix/simplify notification_strip_markup
- Strip markup before interpreting entitites. - Handle *any* tag uniformly (<span> is also handled by pango)
This commit is contained in:
parent
8ee86dc477
commit
bed4877d7b
@ -191,25 +191,8 @@ char *notification_strip_markup(char *str)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
str = string_replace_all(""", "\"", str);
|
||||
str = string_replace_all("'", "'", str);
|
||||
str = string_replace_all("&", "&", str);
|
||||
str = string_replace_all("<", "<", str);
|
||||
str = string_replace_all(">", ">", str);
|
||||
|
||||
/* remove tags */
|
||||
str = string_replace_all("<b>", "", str);
|
||||
str = string_replace_all("</b>", "", str);
|
||||
str = string_replace_all("<br>", " ", str);
|
||||
str = string_replace_all("<br/>", " ", str);
|
||||
str = string_replace_all("<br />", " ", str);
|
||||
str = string_replace_all("<i>", "", str);
|
||||
str = string_replace_all("</i>", "", str);
|
||||
str = string_replace_all("<u>", "", str);
|
||||
str = string_replace_all("</u>", "", str);
|
||||
str = string_replace_all("</a>", "", str);
|
||||
|
||||
while ((start = strstr(str, "<a href")) != NULL) {
|
||||
/* strip all tags */
|
||||
while ((start = strstr(str, "<")) != NULL) {
|
||||
end = strstr(start, ">");
|
||||
if (end != NULL) {
|
||||
replace_buf = strndup(start, end - start + 1);
|
||||
@ -220,16 +203,13 @@ char *notification_strip_markup(char *str)
|
||||
}
|
||||
}
|
||||
|
||||
while ((start = strstr(str, "<img src")) != NULL) {
|
||||
end = strstr(start, "/>");
|
||||
if (end != NULL) {
|
||||
replace_buf = strndup(start, end - start + 2);
|
||||
str = string_replace(replace_buf, "", str);
|
||||
free(replace_buf);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* unquote the remainder */
|
||||
str = string_replace_all(""", "\"", str);
|
||||
str = string_replace_all("'", "'", str);
|
||||
str = string_replace_all("&", "&", str);
|
||||
str = string_replace_all("<", "<", str);
|
||||
str = string_replace_all(">", ">", str);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
@ -270,19 +250,25 @@ char *notification_replace_format(const char *needle, const char *replacement,
|
||||
tmp = notification_quote_markup(tmp);
|
||||
ret = string_replace_all(needle, tmp, haystack);
|
||||
free(tmp);
|
||||
} else if (!allow_markup) {
|
||||
} else {
|
||||
tmp = strdup(replacement);
|
||||
if (!settings.ignore_newline) {
|
||||
if (settings.ignore_newline) {
|
||||
tmp = string_replace_all("<br>", " ", tmp);
|
||||
tmp = string_replace_all("<br/>", " ", tmp);
|
||||
tmp = string_replace_all("<br />", " ", tmp);
|
||||
} else {
|
||||
tmp = string_replace_all("<br>", "\n", tmp);
|
||||
tmp = string_replace_all("<br/>", "\n", tmp);
|
||||
tmp = string_replace_all("<br />", "\n", tmp);
|
||||
}
|
||||
tmp = notification_strip_markup(tmp);
|
||||
tmp = notification_quote_markup(tmp);
|
||||
|
||||
if (!allow_markup) {
|
||||
tmp = notification_strip_markup(tmp);
|
||||
tmp = notification_quote_markup(tmp);
|
||||
}
|
||||
|
||||
ret = string_replace_all(needle, tmp, haystack);
|
||||
free(tmp);
|
||||
} else {
|
||||
ret = string_replace_all(needle, replacement, haystack);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -320,7 +306,7 @@ char *notification_extract_markup_urls(char **str_ptr) {
|
||||
}
|
||||
free(replace_buf);
|
||||
} else {
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
*str_ptr = str;
|
||||
|
Loading…
x
Reference in New Issue
Block a user