From 16bc3155b421cea9be4c04784f924419850fed61 Mon Sep 17 00:00:00 2001 From: Vincent Peng Date: Thu, 8 Oct 2026 22:49:59 +1100 Subject: [PATCH] Forward imageConfig through all MarkdownRenderConfig builders Every withXxx builder except withImageConfig omitted the imageConfig parameter, silently resetting it to .disabled whenever a consumer customized any other config field after enabling images. Forward the existing value so builders compose correctly. Refs #173 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../MarkdownRenderConfig+Builders.swift | 36 ++++++++++------ .../MarkdownRenderConfigBuilderTests.swift | 43 +++++++++++++++++++ 2 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 Tests/MarkdownTextTests/MarkdownRenderConfigBuilderTests.swift diff --git a/Sources/MarkdownText/Models/MarkdownRenderConfig+Builders.swift b/Sources/MarkdownText/Models/MarkdownRenderConfig+Builders.swift index 019cc3fc..cc3ae92b 100644 --- a/Sources/MarkdownText/Models/MarkdownRenderConfig+Builders.swift +++ b/Sources/MarkdownText/Models/MarkdownRenderConfig+Builders.swift @@ -22,7 +22,8 @@ extension MarkdownRenderConfig { codeBlockConfig: codeBlockConfig, blockSpacing: blockSpacing, textSelectionConfig: textSelectionConfig, - thematicBreakColor: thematicBreakColor + thematicBreakColor: thematicBreakColor, + imageConfig: imageConfig ) } @@ -41,7 +42,8 @@ extension MarkdownRenderConfig { codeBlockConfig: codeBlockConfig, blockSpacing: blockSpacing, textSelectionConfig: textSelectionConfig, - thematicBreakColor: thematicBreakColor + thematicBreakColor: thematicBreakColor, + imageConfig: imageConfig ) } @@ -60,7 +62,8 @@ extension MarkdownRenderConfig { codeBlockConfig: codeBlockConfig, blockSpacing: blockSpacing, textSelectionConfig: textSelectionConfig, - thematicBreakColor: thematicBreakColor + thematicBreakColor: thematicBreakColor, + imageConfig: imageConfig ) } @@ -79,7 +82,8 @@ extension MarkdownRenderConfig { codeBlockConfig: codeBlockConfig, blockSpacing: blockSpacing, textSelectionConfig: textSelectionConfig, - thematicBreakColor: thematicBreakColor + thematicBreakColor: thematicBreakColor, + imageConfig: imageConfig ) } @@ -98,7 +102,8 @@ extension MarkdownRenderConfig { codeBlockConfig: codeBlockConfig, blockSpacing: blockSpacing, textSelectionConfig: textSelectionConfig, - thematicBreakColor: thematicBreakColor + thematicBreakColor: thematicBreakColor, + imageConfig: imageConfig ) } @@ -117,7 +122,8 @@ extension MarkdownRenderConfig { codeBlockConfig: codeBlockConfig, blockSpacing: blockSpacing, textSelectionConfig: textSelectionConfig, - thematicBreakColor: thematicBreakColor + thematicBreakColor: thematicBreakColor, + imageConfig: imageConfig ) } @@ -136,7 +142,8 @@ extension MarkdownRenderConfig { codeBlockConfig: codeBlockConfig, blockSpacing: blockSpacing, textSelectionConfig: textSelectionConfig, - thematicBreakColor: thematicBreakColor + thematicBreakColor: thematicBreakColor, + imageConfig: imageConfig ) } @@ -156,7 +163,8 @@ extension MarkdownRenderConfig { codeBlockConfig: codeBlockConfig, blockSpacing: blockSpacing, textSelectionConfig: textSelectionConfig, - thematicBreakColor: thematicBreakColor + thematicBreakColor: thematicBreakColor, + imageConfig: imageConfig ) } @@ -175,7 +183,8 @@ extension MarkdownRenderConfig { codeBlockConfig: codeBlockConfig, blockSpacing: value, textSelectionConfig: textSelectionConfig, - thematicBreakColor: thematicBreakColor + thematicBreakColor: thematicBreakColor, + imageConfig: imageConfig ) } @@ -194,7 +203,8 @@ extension MarkdownRenderConfig { codeBlockConfig: value, blockSpacing: blockSpacing, textSelectionConfig: textSelectionConfig, - thematicBreakColor: thematicBreakColor + thematicBreakColor: thematicBreakColor, + imageConfig: imageConfig ) } @@ -214,7 +224,8 @@ extension MarkdownRenderConfig { codeBlockConfig: codeBlockConfig, blockSpacing: blockSpacing, textSelectionConfig: value, - thematicBreakColor: thematicBreakColor + thematicBreakColor: thematicBreakColor, + imageConfig: imageConfig ) } @@ -233,7 +244,8 @@ extension MarkdownRenderConfig { codeBlockConfig: codeBlockConfig, blockSpacing: blockSpacing, textSelectionConfig: textSelectionConfig, - thematicBreakColor: value + thematicBreakColor: value, + imageConfig: imageConfig ) } diff --git a/Tests/MarkdownTextTests/MarkdownRenderConfigBuilderTests.swift b/Tests/MarkdownTextTests/MarkdownRenderConfigBuilderTests.swift new file mode 100644 index 00000000..2836bae6 --- /dev/null +++ b/Tests/MarkdownTextTests/MarkdownRenderConfigBuilderTests.swift @@ -0,0 +1,43 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. +// + +@testable import SwiftStreamingMarkdown +import XCTest + +final class MarkdownRenderConfigBuilderTests: XCTestCase { + + private var nonDefaultImageConfig: ImageConfig { + ImageConfig(enabled: true, allowedImageTypes: [.remote(allowedDomains: [])]) + } + + func test_builders_preserve_image_config() { + let defaults = MarkdownRenderConfig.default + let base = defaults.withImageConfig(nonDefaultImageConfig) + let builders: [(MarkdownRenderConfig) -> MarkdownRenderConfig] = [ + { $0.withShouldAnimateText(value: true) }, + { $0.withBlockQuoteStyle(value: defaults.blockQuoteStyle) }, + { $0.withHeadingStyle(value: defaults.headingStyle) }, + { $0.withOrderedListStyle(value: defaults.orderedListStyle) }, + { $0.withParagraphStyle(value: defaults.paragraphStyle) }, + { $0.withTableStyle(value: defaults.tableStyle) }, + { $0.withInlineStyle(value: defaults.inlineStyle) }, + { $0.withTextContextMenu(value: nil) }, + { $0.withBlockSpacing(value: defaults.blockSpacing + 1) }, + { $0.withCodeBlockConfig(value: defaults.codeBlockConfig) }, + { $0.withTextSelectionConfig(value: TextSelectionConfig(isEnabled: false)) }, + { $0.withThematicBreakColor(value: defaults.thematicBreakColor) }, + { $0.withImageConfig(.disabled) } + ] + + for (index, apply) in builders.enumerated() { + let updated = apply(base) + if index == builders.count - 1 { + XCTAssertEqual(updated.imageConfig, .disabled, "withImageConfig should replace imageConfig") + } else { + XCTAssertEqual(updated.imageConfig, nonDefaultImageConfig, "builder at index \(index) dropped imageConfig") + } + } + } +}