Skip to content

Don't remove curly braces from alt attribute of an image in MDX #2612

Open
@talatkuyuk

Description

@talatkuyuk

Initial checklist

Affected package

remark-mdx

Steps to reproduce

curly braces {} are removed from alt attribute of an image when parsed by remark-mdx.

This is related with syntax-tree/mdast-util-from-markdown#44

Actual behavior

Regarding with {},

  • mdx expressions in the link (anchor) text for example [**{name}**](...) are interpolated, parsed into inline markdown, and produce a JSX like <strong>{name}</strong> equivalent, as expected in MDX, it is okey.
  • however, in the image alt for example ![{name}](...) produces <img src="..." alt="name">, but should produce <img src="..." alt="{name}"> as the commonmark spec says. If I use double curly braces in alt, one curly braces appear in my tests. ![{{name}}](...) produces <img src="..." alt="{name}">, meaningly mdx parser does not remove all curly braces.

Expected behavior

At least I would expect curly braces are preserved in "alt" once remark-mdx parses since commonmark spec also keeps the curly braces in alt attribute. (see in dingus)

%100 commonmark compliance is always mentioned in the docs!

Curly braces in an image like ![{here}](...) should not be removed, especially considering that MDX is still markdown at its core, just with JSX extensions.

Whereas the title of image/link can hold {} even in MDX, why alt can not hold {} inline with commonmark ? Why I've insisted on that issue this is because of that

As a conclusion, the authors of the MDX spec should allow to appear {} in alt attribute in order to meet the commonmark compliance.

Runtime

node@22

Package manager

npm

Operating system

macos

Build and bundle tools

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    🤞 phase/openPost is being triaged manually

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions