Add rendering as HTML
This commit is contained in:
parent
1778a270d6
commit
2a0d75cf23
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -243,6 +243,21 @@ blockquote {
|
|||
max-height: 1em;
|
||||
}
|
||||
|
||||
/* Twitter */
|
||||
|
||||
.twitterAvatar {
|
||||
vertical-align: middle;
|
||||
border-radius: 4px;
|
||||
height: 24px;
|
||||
width: 24px;
|
||||
}
|
||||
|
||||
.twitterUsername {
|
||||
margin-left: 4px;
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
/*Block ads and junk*/
|
||||
|
||||
iframe[src*="feedads"],
|
||||
|
|
Loading…
Reference in New Issue