mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 19:44:05 +00:00
Add support for HTML img tags (their alts) on the new AttributedStringBuilder
This commit is contained in:
committed by
Stefan Ceriu
parent
b677efc9d2
commit
f33d29b7e9
@@ -229,6 +229,13 @@ struct AttributedStringBuilderV2: AttributedStringBuilderProtocol {
|
|||||||
paragraphStyle.firstLineHeadIndent = CGFloat(indentLevel) * 20
|
paragraphStyle.firstLineHeadIndent = CGFloat(indentLevel) * 20
|
||||||
content.addAttribute(.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: content.length))
|
content.addAttribute(.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: content.length))
|
||||||
|
|
||||||
|
case "img":
|
||||||
|
if let alt = try? childElement.attr("alt"), !alt.isEmpty {
|
||||||
|
content = NSMutableAttributedString(string: "[img: \(alt)]")
|
||||||
|
} else {
|
||||||
|
content = NSMutableAttributedString(string: "[img]")
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
content = attributedString(element: childElement, documentBody: documentBody, preserveFormatting: preserveFormatting, listTag: listTag, listIndex: &childIndex, indentLevel: indentLevel)
|
content = attributedString(element: childElement, documentBody: documentBody, preserveFormatting: preserveFormatting, listTag: listTag, listIndex: &childIndex, indentLevel: indentLevel)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -723,6 +723,21 @@ class AttributedStringBuilderV1Tests: XCTestCase {
|
|||||||
XCTAssertEqual(foundAttachments, 2)
|
XCTAssertEqual(foundAttachments, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testImageTags() {
|
||||||
|
let htmlString = "Hey <img src=\"smiley.gif\" alt=\"Smiley face\">! How's work<img src=\"workplace.jpg\">?"
|
||||||
|
|
||||||
|
guard let attributedString = attributedStringBuilder.fromHTML(htmlString) else {
|
||||||
|
XCTFail("Could not build the attributed string")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if AttributedStringBuilder.useNextGenHTMLParser {
|
||||||
|
XCTAssertEqual(String(attributedString.characters), "Hey [img: Smiley face]! How's work[img]?")
|
||||||
|
} else {
|
||||||
|
XCTAssertEqual(String(attributedString.characters), "Hey ! How's work?") // No bueno
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Phishing prevention
|
// MARK: - Phishing prevention
|
||||||
|
|
||||||
func testPhishingLink() {
|
func testPhishingLink() {
|
||||||
|
|||||||
Reference in New Issue
Block a user