Add support for <details> and <summary> tags (#6077)

This commit is contained in:
Stefan Ceriu
2026-09-03 11:47:12 +03:00
committed by GitHub
parent 7052751e38
commit 4355307ba0
15 changed files with 134 additions and 22 deletions
@@ -242,6 +242,31 @@ struct AttributedStringBuilderTests {
#expect(foundLink)
}
@Test
func detailsAndSummary() throws {
let htmlString = "Before<details><summary>Expand me</summary><p>Hidden content</p></details>After"
let attributedString = try #require(attributedStringBuilder.fromHTML(htmlString), "Could not build the attributed string")
#expect(String(attributedString.characters) == "BeforeHidden content\nAfter")
let components = attributedString.formattedComponents
#expect(components.count == 3)
#expect(components.map(\.type) == [.plainText, .details(summary: "Expand me"), .plainText])
#expect(components[1].attributedString.string == "Hidden content")
}
@Test
func detailsWithoutSummary() throws {
let htmlString = "<details><p>Content</p></details>"
let attributedString = try #require(attributedStringBuilder.fromHTML(htmlString), "Could not build the attributed string")
#expect(String(attributedString.characters) == "Content")
#expect(attributedString.formattedComponents.map(\.type) == [.details(summary: L10n.a11yViewDetails)])
}
@Test
func singleBlockquote() throws {
let htmlString = "<blockquote>Blockquote</blockquote><p>Another paragraph</p>"