nuxt / content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
https://content.nuxt.com
MIT License
3k stars 605 forks source link

Variable binding in Markdown causes anchor links to fail #2637

Closed kaceo closed 3 weeks ago

kaceo commented 1 month ago

Environment

Reproduction

See below

Describe the bug

In a markdown file, if an anchor link contains a variable substition, it does not become a link

e.g.

---
mypath: /geography
---
Mypath is {{ $doc.mypath }}
[Go there]({{ $doc.mypath }}/welcome)

After nuxt runs, line 1 creates a line of text correctly substituted.

Line 2 creates the substitution correctly but Markdown does not change it into an anchor:

My path is /geography
[Go there](/geography/welcome)

Additional context

No response

Logs

No response

kaceo commented 1 month ago

My analysis is that the sequence of conversion inside Markdown is incorrect.

In Vitepress there is also a similar feature of embedding frontmatter variables inside content, and it uses the early binding strategy. Embedded Vue components are processed at the end. This work flow creates the correct conversion of Markdown with embedded variables and components without breaking any Markdown syntax.

farnabaz commented 3 weeks ago

Hello @kaceo Nuxt Content bind variables at render time, That's why the second line did not convert to anchor link (because it is not a valid link format). Variable binding in Content module is designed to render dynamic data and not replacing static text in parse time.

Early binding can be implemented using Content transformers by replacing bindings before parsing the markdown.