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
@@ -17,10 +17,11 @@ nonisolated extension AttributedString {
var formattedComponents: [AttributedStringBuilderComponent] {
var components = [AttributedStringBuilderComponent]()
for run in runs[\.blockquote, \.codeBlock] {
for run in runs[\.blockquote, \.codeBlock, \.details] {
let isBlockquote = run.0 != nil
let isCodeBlock = run.1 != nil
var attributedString = AttributedString(self[run.2])
let details = run.2
var attributedString = AttributedString(self[run.3])
// Remove trailing new lines if any
if attributedString.characters.last?.isNewline ?? false,
@@ -28,12 +29,14 @@ nonisolated extension AttributedString {
attributedString.removeSubrange(range)
}
let componentType: AttributedStringBuilderComponent.ComponentType = switch (isBlockquote, isCodeBlock) {
case (true, _):
let componentType: AttributedStringBuilderComponent.ComponentType = switch (details, isBlockquote, isCodeBlock) {
case (.some(let summary), _, _):
.details(summary: summary)
case (_, true, _):
.blockquote
case (false, true):
case (_, false, true):
.codeBlock
case (false, false):
case (_, false, false):
.plainText
}