Modularize Image Provider Implementation for Improved Flexibility #409
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This MR offers a restructure of the Swift Package in a modularized way.
Background:
This package is excellent—it provides a lightweight wrapper around cmark and integrates seamlessly with SwiftUI for Markdown rendering. However, it currently introduces a tight dependency on the NetworkImage framework, which may discourage adoption by teams or organizations that are cautious about introducing new networking dependencies.
Fortunately, the framework already provides abstractions for customizable image providers, such as ImageProvider and InlineImageProvider. With some restructuring, we can further decouple the framework and modularize its components.
Changes
This PR introduces two new Swift Package targets:
ImageProviders: Contains the core ImageProvider abstractions and a default asset-based implementation.
NetworkImageProviders: A separate target that builds on ImageProviders and adds the two existing NetworkImage-based providers. This target has a dependency on the NetworkImage package.
Benefits:
Improved modularity: This restructuring enhances separation of concerns and removes hard dependencies from the core Markdown rendering logic.
Greater flexibility for adopters: Projects that prefer not to include NetworkImage (or use custom image loading solutions) can now adopt swift-markdown-ui more easily.
Optimized builds: This change improves caching performance for build systems like Bazel, Buck, and Tuist, allowing more targeted invalidation of build artifacts.
Path for future extensibility: Encourages the development of custom image providers without needing to fork or heavily modify the framework.
Breaking changes:
Summary:
This PR introduces a thoughtful and backward-compatible restructuring of the image provider system within swift-markdown-ui. While it involves minor changes to how some modules are imported, it preserves the existing API and enhances the flexibility, modularity, and maintainability of the framework.
I believe this change aligns well with the project's philosophy of lightweight and composable design, and it lays the groundwork for broader adoption across diverse codebases. I hope the maintainers will consider including it in the next major release.