Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable binding in Markdown causes anchor links to fail #2637

Closed
kaceo opened this issue May 15, 2024 · 2 comments
Closed

Variable binding in Markdown causes anchor links to fail #2637

kaceo opened this issue May 15, 2024 · 2 comments

Comments

@kaceo
Copy link

kaceo commented May 15, 2024

Environment

  • Operating System: Linux
  • Node Version: v18.17.1
  • Nuxt Version: 3.11.2
  • CLI Version: 3.11.1
  • Nitro Version: 2.9.6

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
Copy link
Author

kaceo commented May 15, 2024

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

  • if the variable substition is done at the end (after the entire page is converted to a Vue page), it will not be recognised by Anchor.

  • on the other hand, if the variable substitution is done early, it will allow the correct text replacement to appear inside the Markdown text, and be recognised by Anchor.

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
Copy link
Member

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.

@farnabaz farnabaz closed this as not planned Won't fix, can't repro, duplicate, stale May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants