Skip to content

Markdown image links render as empty content #53

Description

@xinnjie

Description

StructuredText(markdown:) does not render Markdown image links where an image is used as the link content:

[![](https://example.com/a.png)](https://example.com/b.png)

This is valid Markdown and same as

<a href="https://example.com/b.png">
  <img src="https://example.com/a.png" alt="">
</a>

In this case, Textual currently renders no visible content for the linked image. A plain image renders correctly:

![](https://example.com/a.png)

The issue appears to come from the Foundation AttributedString(markdown:) parser path used by Textual. For example:

let markdown = "[![](https://example.com/a.png)](https://example.com/b.png)"
let attributedString = try AttributedString(markdown: markdown)

print(String(attributedString.characters)) // ""
print(attributedString.runs.count)         // 0

Since the parsed attributed string contains no runs, Textual's image attachment loader does not get a chance to load or render the image.

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

StructuredText(markdown:) should render the image from the nested image markdown:

![](https://example.com/a.png)

Ideally, the image should also preserve the outer link destination:

https://example.com/b.png

If preserving the clickable image link is not currently possible, rendering the image without dropping the content would still be preferable to rendering nothing.

Actual behavior

The linked image markdown renders as empty content. No image is displayed.

Steps to reproduce

Use Textual with Markdown containing an image wrapped in a link:

import SwiftUI
import Textual

struct ContentView: View {
  var body: some View {
    StructuredText(
      markdown: "[![](https://example.com/a.png)](https://example.com/b.png)"
    )
    .textual.imageAttachmentLoader(.image())
  }
}

Compare it with the plain image version, which renders as expected:

StructuredText(markdown: "![](https://example.com/a.png)")
  .textual.imageAttachmentLoader(.image())

Textual version information

0.3.1

Destination operating system

macOS 26.3.1

Xcode version information

Xcode 26.3
Build version 17C529

Swift Compiler version information

swift-driver version: 1.127.15 Apple Swift version 6.2.4 (swiftlang-6.2.4.1.4 clang-1700.6.4.2)
Target: arm64-apple-macosx26.0

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