diff --git a/Sources/MarkdownUI/Rendering/AttributedStringRenderer.swift b/Sources/MarkdownUI/Rendering/AttributedStringRenderer.swift index ba6324e8..f2ebe7fc 100644 --- a/Sources/MarkdownUI/Rendering/AttributedStringRenderer.swift +++ b/Sources/MarkdownUI/Rendering/AttributedStringRenderer.swift @@ -353,7 +353,7 @@ extension AttributedStringRenderer { result.addAttribute( .paragraphStyle, - value: paragraphStyle(state: state), + value: paragraphStyle(state: state, alignment: .natural), range: NSRange(0.. NSParagraphStyle { + private func paragraphStyle(state: State, alignment: NSTextAlignment? = nil) -> NSParagraphStyle { let pointSize = state.font.resolve(sizeCategory: environment.sizeCategory).pointSize let result = NSMutableParagraphStyle() result.setParagraphStyle(.default) result.baseWritingDirection = environment.baseWritingDirection - result.alignment = environment.alignment + result.alignment = alignment ?? environment.alignment result.lineSpacing = environment.lineSpacing result.paragraphSpacing = round(pointSize * state.paragraphSpacing) result.headIndent = round(pointSize * state.headIndent) diff --git a/Tests/MarkdownUITests/MarkdownTests.swift b/Tests/MarkdownUITests/MarkdownTests.swift index 92ccab52..a2c04d2f 100644 --- a/Tests/MarkdownUITests/MarkdownTests.swift +++ b/Tests/MarkdownUITests/MarkdownTests.swift @@ -397,6 +397,33 @@ assertSnapshot(matching: view, as: .image(layout: layout), named: platformName) } + func testThematicBreakAndCenterAlignment() { + let view = Markdown( + #""" + # SwiftUI + + Declare the user interface and behavior for your app + on every platform. + + --- + + ## Overview + + SwiftUI provides views, controls, and layout structures + for declaring your app’s user interface. + + --- + + ― From Apple Developer Documentation + """# + ) + .multilineTextAlignment(.center) + .background(Color.orange) + .padding() + + assertSnapshot(matching: view, as: .image(layout: layout), named: platformName) + } + func testInlines() { let view = Markdown( #""" diff --git a/Tests/MarkdownUITests/__Snapshots__/MarkdownTests/testThematicBreakAndCenterAlignment.iOS.png b/Tests/MarkdownUITests/__Snapshots__/MarkdownTests/testThematicBreakAndCenterAlignment.iOS.png new file mode 100644 index 00000000..462fde49 Binary files /dev/null and b/Tests/MarkdownUITests/__Snapshots__/MarkdownTests/testThematicBreakAndCenterAlignment.iOS.png differ diff --git a/Tests/MarkdownUITests/__Snapshots__/MarkdownTests/testThematicBreakAndCenterAlignment.tvOS.png b/Tests/MarkdownUITests/__Snapshots__/MarkdownTests/testThematicBreakAndCenterAlignment.tvOS.png new file mode 100644 index 00000000..12b5471a Binary files /dev/null and b/Tests/MarkdownUITests/__Snapshots__/MarkdownTests/testThematicBreakAndCenterAlignment.tvOS.png differ