mdx-js / mdx

Markdown for the component era
https://mdxjs.com
MIT License
17.77k stars 1.14k forks source link

Dynamic linked heading does not interpolate link properly #2493

Closed sumanthratna closed 5 months ago

sumanthratna commented 5 months ago

Initial checklist

Affected packages and versions

3.0.1

Link to runnable example

Steps to reproduce

This is my MDX file:

export const metadata = {
  path: "/blog/new-post",
  title: "This is a Fake Title",
};

# <>[{metadata.title}]({metadata.path})</>

hey again

Expected behavior

The above MDX should render the following HTML after interpolating metadata.path:

<h1><a href="/blog/new-post">This is a Fake Title</a></h1>
<p>hey again</p>

Actual behavior

The above MDX renders the following HTML:

<h1><a href="%7Bmetadata.path%7D">This is a Fake Title</a></h1>
<p>hey again</p>

Note that the link text is interpolated properly, but not the link href.

Runtime

Node v21

Package manager

yarn v4

OS

macOS

Build and bundle tools

Next.js

wooorm commented 5 months ago

Hey!

That is indeed not something that works. It is intentional. MDX is not a template language.

# <a href={metadata.path}>{metadata.title}</a>
sumanthratna commented 5 months ago

Thanks for clarifying @wooorm! I am still a little confused about the mechanics of interpolation.

The following does not interpolate the title:

# `{metadata.title}`

The following does:

# ~**_{metadata.title}_**~

Is there a rule to understand which Markdown features result in interpolation?

ChristianMurphy commented 5 months ago

Code will never interpolate. Inlines (strong, emphasis, strike) usually will.