Skip to content

Commit f7ec387

Browse files
committed
Attributed renderer
1 parent 14c27f5 commit f7ec387

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Sources/MarkdownUI/Renderer/AttributedStringInlineRenderer.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ extension InlineNode {
44
func renderAttributedString(
55
baseURL: URL?,
66
textStyles: InlineTextStyles,
7+
softBreakMode: SoftBreak.Mode,
78
attributes: AttributeContainer
89
) -> AttributedString {
910
var renderer = AttributedStringInlineRenderer(
1011
baseURL: baseURL,
1112
textStyles: textStyles,
13+
softBreakMode: softBreakMode,
1214
attributes: attributes
1315
)
1416
renderer.render(self)
@@ -21,12 +23,19 @@ private struct AttributedStringInlineRenderer {
2123

2224
private let baseURL: URL?
2325
private let textStyles: InlineTextStyles
26+
private let softBreakMode: SoftBreak.Mode
2427
private var attributes: AttributeContainer
2528
private var shouldSkipNextWhitespace = false
2629

27-
init(baseURL: URL?, textStyles: InlineTextStyles, attributes: AttributeContainer) {
30+
init(
31+
baseURL: URL?,
32+
textStyles: InlineTextStyles,
33+
softBreakMode: SoftBreak.Mode,
34+
attributes: AttributeContainer
35+
) {
2836
self.baseURL = baseURL
2937
self.textStyles = textStyles
38+
self.softBreakMode = softBreakMode
3039
self.attributes = attributes
3140
}
3241

@@ -67,10 +76,13 @@ private struct AttributedStringInlineRenderer {
6776
}
6877

6978
private mutating func renderSoftBreak() {
70-
if self.shouldSkipNextWhitespace {
79+
switch softBreakMode {
80+
case .space where self.shouldSkipNextWhitespace:
7181
self.shouldSkipNextWhitespace = false
72-
} else {
82+
case .space:
7383
self.result += .init(" ", attributes: self.attributes)
84+
case .lineBreak:
85+
self.renderLineBreak()
7486
}
7587
}
7688

Sources/MarkdownUI/Renderer/TextInlineRenderer.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ private struct TextInlineRenderer {
115115
inline.renderAttributedString(
116116
baseURL: self.baseURL,
117117
textStyles: self.textStyles,
118+
softBreakMode: self.softBreakMode,
118119
attributes: self.attributes
119120
)
120121
)

0 commit comments

Comments
 (0)