diff --git a/ElementX/Sources/Other/HTMLParsing/AttributedStringBuilderV2.swift b/ElementX/Sources/Other/HTMLParsing/AttributedStringBuilderV2.swift index 64961deb6..e90eb4edc 100644 --- a/ElementX/Sources/Other/HTMLParsing/AttributedStringBuilderV2.swift +++ b/ElementX/Sources/Other/HTMLParsing/AttributedStringBuilderV2.swift @@ -229,6 +229,13 @@ struct AttributedStringBuilderV2: AttributedStringBuilderProtocol { paragraphStyle.firstLineHeadIndent = CGFloat(indentLevel) * 20 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: content = attributedString(element: childElement, documentBody: documentBody, preserveFormatting: preserveFormatting, listTag: listTag, listIndex: &childIndex, indentLevel: indentLevel) } diff --git a/UnitTests/Sources/AttributedStringBuilderTests.swift b/UnitTests/Sources/AttributedStringBuilderTests.swift index 763f8a0ff..7b6c6553b 100644 --- a/UnitTests/Sources/AttributedStringBuilderTests.swift +++ b/UnitTests/Sources/AttributedStringBuilderTests.swift @@ -723,6 +723,21 @@ class AttributedStringBuilderV1Tests: XCTestCase { XCTAssertEqual(foundAttachments, 2) } + func testImageTags() { + let htmlString = "Hey \"Smiley! How's work?" + + 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 func testPhishingLink() {