Skip to content

Expose resolveImageLink and resolveImageAlt as public for custom image components #577

@yueban

Description

@yueban

Bug Description

With the changes introduced in 0.41.0 to image rendering, the logic to extract an image's link, alt text, and the hover tooltip behavior was encapsulated into several helper functions:

  • ASTNode.resolveImageLink(content, referenceLinkHandler)
  • ASTNode.resolveImageAlt(content)
  • ImageAltTooltip(alt, content)

However, because these functions and composables are marked as internal, developers trying to define a custom image component via MarkdownComponents cannot access them.

Steps to Reproduce

When attempting to implement a custom image renderer that still utilizes the built-in tooltip behavior and resolution utilities, we hit compilation barriers:

val customImageComponent: MarkdownComponent = { model ->
    // We want to resolve the link and alt text to feed into our custom Composable
    val link = model.node.resolveImageLink(model.content, LocalReferenceLinkHandler.current) // Unresolved reference (internal)
    val alt = model.node.resolveImageAlt(model.content) // Unresolved reference (internal)

    // We want to keep the tooltip wrapper for our custom renderer
    ImageAltTooltip(alt) { // Unresolved reference (internal)
        MyCustomImageRenderer(link, alt)
    }
}

Currently, to get around this, we are forced to copy and paste both the AST-traversal logic and the platform-specific tooltip wrapper logic directly into our local projects.

Expected Behavior

Changing the visibility of these helpers and the composable wrapper from internal to public would allow consumers to cleanly override image components while reusing the core parsing and styling utilities provided by the library.

Checklist

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions