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

Print variable values in code snippets #471

Closed
4 tasks done
deevannaveed opened this issue Dec 14, 2021 · 3 comments · Fixed by #1759
Closed
4 tasks done

Print variable values in code snippets #471

deevannaveed opened this issue Dec 14, 2021 · 3 comments · Fixed by #1759
Labels
enhancement New feature or request

Comments

@deevannaveed
Copy link

deevannaveed commented Dec 14, 2021

Is your feature request related to a problem? Please describe.

Basically I want to add dynamic values in code snippets see the example below, I want the links to have a dynamic version number.

MyMarkDown.md

<script setup>
  import { version } from '../../../packages/myPackage/package.json'
</script>
# Below is a code snippet that will contain our latest version.

```html
<!-- stylesheet -->
<link rel="stylesheet" href="https://mycdn.com/css/{{ version }}/style.min.css" />

<div>Some content</div>

<!-- 🚨 Script must be loaded after the component -->
<script src="https://mycdn.com/js/{{ version }}/script.min.js" ></script>

Describe the solution you'd like

I want to be able to print dynamic values in code snippets as show in the example above.

Describe alternatives you've considered

No response

Additional context

No response

Validations

@kiaking
Copy link
Member

kiaking commented May 23, 2022

Interesting 👀 Not sure how to achieve this, but if anyone knows a good way to do it, I'm curious to know.

@kiaking kiaking added the enhancement New feature or request label May 23, 2022
@brc-dd
Copy link
Member

brc-dd commented Jun 29, 2022

We are adding v-pre here: https://cs.github.com/vuejs/vitepress/blob/19b0758a04e9fb7863b3a961024dfe1137fbe928/src/node/markdown/plugins/highlight.ts

I have a suggestion, users can do something like this:

```foo-vue
Don't add v-pre if -vue suffix is there.
Also remove suffix from lang so that highlighter don't complaint.
```

```foo
Otherwise add v-pre.
```

@brc-dd
Copy link
Member

brc-dd commented Oct 27, 2022

Okay so this doesn't always work. Since markdown parser is run first, {{ }} syntax may get highlighted so vue won't be able to substitute the values. For example in this result:

<span style="color: #A6ACCD">(</span><span style="color: #89DDFF">{</span><span style="color: #A6ACCD">{ z </span><span style="color: #89DDFF">}</span><span style="color: #A6ACCD">})</span>

brc-dd added a commit that referenced this issue Oct 27, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants