Fix posts with multiple <p> tags being handled incorrectly
This commit is contained in:
parent
bea738e0ec
commit
c155f695f5
|
@ -0,0 +1,28 @@
|
|||
//
|
||||
// AttributedString+Trim.swift
|
||||
// Tusker
|
||||
//
|
||||
// Created by Shadowfacts on 8/29/18.
|
||||
// Copyright © 2018 Shadowfacts. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension NSMutableAttributedString {
|
||||
|
||||
func trimCharactersInSet(_ charSet: CharacterSet) {
|
||||
var range = (string as NSString).rangeOfCharacter(from: charSet)
|
||||
|
||||
while range.length != 0 && range.location == 0 {
|
||||
replaceCharacters(in: range, with: "")
|
||||
range = (string as NSString).rangeOfCharacter(from: charSet)
|
||||
}
|
||||
|
||||
range = (string as NSString).rangeOfCharacter(from: charSet, options: .backwards)
|
||||
while range.length != 0 && range.length + range.location == length {
|
||||
replaceCharacters(in: range, with: "")
|
||||
range = (string as NSString).rangeOfCharacter(from: charSet, options: .backwards)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -119,6 +119,7 @@ class HTMLContentLabel: UILabel {
|
|||
let (attributedText, links) = attributedTextForHTMLNode(body)
|
||||
self.links = links
|
||||
let mutAttrString = NSMutableAttributedString(attributedString: attributedText)
|
||||
mutAttrString.trimCharactersInSet(.whitespacesAndNewlines)
|
||||
mutAttrString.addAttribute(.font, value: font, range: NSRange(location: 0, length: mutAttrString.length))
|
||||
self.attributedText = mutAttrString
|
||||
}
|
||||
|
@ -153,6 +154,8 @@ class HTMLContentLabel: UILabel {
|
|||
|
||||
links[linkRange] = url
|
||||
}
|
||||
case "p":
|
||||
attributed.append(NSAttributedString(string: "\n\n"))
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue