Skip to content

Commit f329755

Browse files
authored
add a TextAttribute to links when available. (#2)
This allows the app using the library to add a pressed state for links.
1 parent e91ce05 commit f329755

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

Sources/MarkdownUI/Renderer/TextInlineRenderer.swift

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,23 @@ private struct TextInlineRenderer {
114114
}
115115

116116
private mutating func defaultRender(_ inline: InlineNode) {
117-
self.result =
118-
self.result
119-
+ Text(
120-
inline.renderAttributedString(
121-
baseURL: self.baseURL,
122-
textStyles: self.textStyles,
123-
softBreakMode: self.softBreakMode,
124-
attributes: self.attributes
125-
)
117+
var text = Text(
118+
inline.renderAttributedString(
119+
baseURL: self.baseURL,
120+
textStyles: self.textStyles,
121+
softBreakMode: self.softBreakMode,
122+
attributes: self.attributes
126123
)
124+
)
125+
if #available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *), case .link(let destination, _) = inline {
126+
text = text.customAttribute(LinkAttribute(urlString: destination))
127+
}
128+
129+
self.result = self.result + text
127130
}
128131
}
132+
133+
@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *)
134+
public struct LinkAttribute: TextAttribute {
135+
public let urlString: String
136+
}

0 commit comments

Comments
 (0)