Add attributed title support in the timeline

This commit is contained in:
Nate Weaver
2020-04-30 02:36:32 -05:00
parent ec49030081
commit c555646fb2
6 changed files with 81 additions and 5 deletions

View File

@@ -52,8 +52,8 @@ struct ArticleStringFormatter {
return s
}
static func truncatedTitle(_ article: Article) -> String {
guard let title = article.title else {
static func truncatedTitle(_ article: Article, forHTML: Bool = false) -> String {
guard let title = article.sanitizedTitle(forHTML: forHTML) else {
return ""
}
@@ -64,7 +64,11 @@ struct ArticleStringFormatter {
var s = title.replacingOccurrences(of: "\n", with: "")
s = s.replacingOccurrences(of: "\r", with: "")
s = s.replacingOccurrences(of: "\t", with: "")
s = s.rsparser_stringByDecodingHTMLEntities()
if !forHTML {
s = s.rsparser_stringByDecodingHTMLEntities()
}
s = s.trimmingWhitespace
s = s.collapsingWhitespace
@@ -79,6 +83,13 @@ struct ArticleStringFormatter {
return s
}
static func attributedTruncatedTitle(_ article: Article) -> NSAttributedString {
let title = truncatedTitle(article, forHTML: true)
let data = title.data(using: .utf8)!
let attributed = NSAttributedString(html: data, documentAttributes: nil)!
return attributed
}
static func truncatedSummary(_ article: Article) -> String {
guard let body = article.body else {
return ""