mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
strip html from entry titles (closes #329)
This commit is contained in:
@@ -40,7 +40,7 @@ import com.steadystate.css.parser.CSSOMParser;
|
||||
public class FeedUtils {
|
||||
|
||||
protected static Logger log = LoggerFactory.getLogger(FeedUtils.class);
|
||||
|
||||
|
||||
private static final List<String> ALLOWED_IFRAME_CSS_RULES = Arrays.asList(
|
||||
"height", "width", "border");
|
||||
private static final char[] DISALLOWED_IFRAME_CSS_RULE_CHARACTERS = new char[] {
|
||||
@@ -105,7 +105,8 @@ public class FeedUtils {
|
||||
return encoding;
|
||||
}
|
||||
|
||||
public static String handleContent(String content, String baseUri) {
|
||||
public static String handleContent(String content, String baseUri,
|
||||
boolean keepTextOnly) {
|
||||
if (StringUtils.isNotBlank(content)) {
|
||||
baseUri = StringUtils.trimToEmpty(baseUri);
|
||||
Whitelist whitelist = new Whitelist();
|
||||
@@ -158,8 +159,12 @@ public class FeedUtils {
|
||||
|
||||
clean.outputSettings(new OutputSettings().escapeMode(
|
||||
EscapeMode.base).prettyPrint(false));
|
||||
content = clean.body().html();
|
||||
|
||||
Element body = clean.body();
|
||||
if (keepTextOnly) {
|
||||
content = body.text();
|
||||
} else {
|
||||
content = body.html();
|
||||
}
|
||||
}
|
||||
return content;
|
||||
}
|
||||
@@ -375,8 +380,8 @@ public class FeedUtils {
|
||||
for (Element element : elements) {
|
||||
String href = element.attr("src");
|
||||
if (href != null) {
|
||||
String proxy = removeTrailingSlash(publicUrl) + "/rest/server/proxy?u="
|
||||
+ imageProxyEncoder(href);
|
||||
String proxy = removeTrailingSlash(publicUrl)
|
||||
+ "/rest/server/proxy?u=" + imageProxyEncoder(href);
|
||||
element.attr("src", proxy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,11 +43,10 @@ public class FeedUpdateService {
|
||||
FeedEntry update = null;
|
||||
if (existing == null) {
|
||||
FeedEntryContent content = entry.getContent();
|
||||
content.setTitle(FeedUtils.truncate(
|
||||
FeedUtils.handleContent(content.getTitle(), feed.getLink()),
|
||||
2048));
|
||||
content.setTitle(FeedUtils.truncate(FeedUtils.handleContent(
|
||||
content.getTitle(), feed.getLink(), true), 2048));
|
||||
content.setContent(FeedUtils.handleContent(content.getContent(),
|
||||
feed.getLink()));
|
||||
feed.getLink(), false));
|
||||
|
||||
entry.setInserted(Calendar.getInstance().getTime());
|
||||
entry.getFeeds().add(feed);
|
||||
|
||||
Reference in New Issue
Block a user