mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Add rendering as HTML
This commit is contained in:
@@ -53,7 +53,40 @@ final class TwitterStatus: Codable {
|
||||
}
|
||||
|
||||
func renderAsHTML() -> String? {
|
||||
return nil
|
||||
if let retweetedStatus = retweetedStatus {
|
||||
return renderAsRetweetHTML(retweetedStatus)
|
||||
}
|
||||
if let quotedStatus = quotedStatus {
|
||||
return renderAsQuoteHTML(quotedStatus)
|
||||
}
|
||||
return renderAsTweetHTML(self)
|
||||
}
|
||||
|
||||
func renderAsTweetHTML(_ status: TwitterStatus) -> String? {
|
||||
return status.displayText
|
||||
}
|
||||
|
||||
func renderAsRetweetHTML(_ status: TwitterStatus) -> String {
|
||||
var html = String()
|
||||
html += "<blockquote>"
|
||||
if let userHTML = status.user?.renderHTML() {
|
||||
html += userHTML
|
||||
}
|
||||
html += renderAsTweetHTML(status) ?? ""
|
||||
html += "</blockquote>"
|
||||
return html
|
||||
}
|
||||
|
||||
func renderAsQuoteHTML(_ quotedStatus: TwitterStatus) -> String {
|
||||
var html = String()
|
||||
html += renderAsTweetHTML(self) ?? ""
|
||||
html += "<blockquote>"
|
||||
if let userHTML = quotedStatus.user?.renderHTML() {
|
||||
html += userHTML
|
||||
}
|
||||
html += renderAsTweetHTML(quotedStatus) ?? ""
|
||||
html += "</blockquote>"
|
||||
return html
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,4 +24,21 @@ struct TwitterUser: Codable {
|
||||
return "https://twitter.com/\(screenName ?? "")"
|
||||
}
|
||||
|
||||
func renderHTML() -> String? {
|
||||
var html = String()
|
||||
html += "<div><a href=\"\(url)\">"
|
||||
if let avatarURL = avatarURL {
|
||||
html += "<img class=\"twitterAvatar\" src=\"\(avatarURL)\">"
|
||||
}
|
||||
html += "<span class=\"twitterUsername\">"
|
||||
if let name = name {
|
||||
html += " \(name)"
|
||||
}
|
||||
if let screenName = screenName {
|
||||
html += " @\(screenName)"
|
||||
}
|
||||
html += "</span></a></div>"
|
||||
return html
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user