Skip to content

Commit

Permalink
fix link not clickable in news (drop support for <img> tags for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedley committed Nov 18, 2019
1 parent 471cf0e commit b4c2141
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions appdb/Tabs/Settings/News/News+Detail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,27 +167,31 @@ extension AttributedLabel {
let link = Style("a").foregroundColor(UIColor(rgba: "#446CB3"), .normal).foregroundColor(UIColor(rgba: "#486A92"), .highlighted)
.underlineStyle(.single)

// TODO: add support for showing images in <img> tags. Currently there's a way but it screws up detections
// See https://github.com/psharanda/Atributika/issues/54

// Supports <img>
let img = Style("img")
//let img = Style("img")

// Close <img> tag manually (otherwise it's not detected)
var newText = text
if text.contains("<img src") {
let tmp = text.components(separatedBy: "<img src")[1].components(separatedBy: ">")[0]
newText = text.replacingOccurrences(of: tmp + ">", with: tmp + "></img>")
}
//var newText = text
//if text.contains("<img src") {
// let tmp = text.components(separatedBy: "<img src")[1].components(separatedBy: ">")[0]
// newText = text.replacingOccurrences(of: tmp + ">", with: tmp + "></img>")
//}

// Apply styles
let str = newText.style(tags: [b, i, strong, u, img, link], transformers: transformers)
let str = text.style(tags: [b, i, strong, u,/* img,*/ link], transformers: transformers).styleLinks(link)

// Create NSMutableAttributedString
let mutableAttrStr = NSMutableAttributedString(attributedString: str.attributedString)
//let mutableAttrStr = NSMutableAttributedString(attributedString: str.attributedString)

// Insert image if <img> tag is found
addImageSupport(mutableAttrStr: mutableAttrStr, detections: str.detections)
//addImageSupport(mutableAttrStr: mutableAttrStr, detections: str.detections)

// Update text
attributedText = mutableAttrStr.styleLinks(link)
//attributedText = mutableAttrStr.styleLinks(link)
attributedText = str

// Click on url detection
onClick = { label, detection in
Expand Down

0 comments on commit b4c2141

Please sign in to comment.