Add attributed title support in the timeline

This commit is contained in:
Nate Weaver
2020-04-07 16:05:13 -05:00
parent 4ddb6c8d4f
commit 3d509a94d4
8 changed files with 155 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 ""