Skip to content

Modularize Image Provider Implementation for Improved Flexibility #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

danibachar
Copy link

@danibachar danibachar commented Jun 6, 2025

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:

  • This update changes how some symbols are imported, especially for those using NetworkImage-based providers. However, the public API remains unchanged for most users.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants