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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = string_replace_all(""", "\"", str);
|
/* strip all tags */
|
||||||
str = string_replace_all("'", "'", str);
|
while ((start = strstr(str, "<")) != NULL) {
|
||||||
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) {
|
|
||||||
end = strstr(start, ">");
|
end = strstr(start, ">");
|
||||||
if (end != NULL) {
|
if (end != NULL) {
|
||||||
replace_buf = strndup(start, end - start + 1);
|
replace_buf = strndup(start, end - start + 1);
|
||||||
@ -220,16 +203,13 @@ char *notification_strip_markup(char *str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((start = strstr(str, "<img src")) != NULL) {
|
/* unquote the remainder */
|
||||||
end = strstr(start, "/>");
|
str = string_replace_all(""", "\"", str);
|
||||||
if (end != NULL) {
|
str = string_replace_all("'", "'", str);
|
||||||
replace_buf = strndup(start, end - start + 2);
|
str = string_replace_all("&", "&", str);
|
||||||
str = string_replace(replace_buf, "", str);
|
str = string_replace_all("<", "<", str);
|
||||||
free(replace_buf);
|
str = string_replace_all(">", ">", str);
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,19 +250,25 @@ char *notification_replace_format(const char *needle, const char *replacement,
|
|||||||
tmp = notification_quote_markup(tmp);
|
tmp = notification_quote_markup(tmp);
|
||||||
ret = string_replace_all(needle, tmp, haystack);
|
ret = string_replace_all(needle, tmp, haystack);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
} else if (!allow_markup) {
|
} else {
|
||||||
tmp = strdup(replacement);
|
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 = 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);
|
ret = string_replace_all(needle, tmp, haystack);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
} else {
|
|
||||||
ret = string_replace_all(needle, replacement, haystack);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -320,7 +306,7 @@ char *notification_extract_markup_urls(char **str_ptr) {
|
|||||||
}
|
}
|
||||||
free(replace_buf);
|
free(replace_buf);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*str_ptr = str;
|
*str_ptr = str;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user