padarom / vuepress-plugin-code-switcher

:arrows_clockwise: Component that adds synchronized multi-language code blocks to your Vuepress sites
https://code-switcher.padarom.xyz
MIT License
41 stars 6 forks source link

possible to pass page variables into code block? #7

Closed ssuess closed 2 years ago

ssuess commented 2 years ago

Hi is it possible to pass vuepress page variables into the code blocks? I have been trying unsuccessfully with variations of:

<CodeSwitcher>
<template v-slot:curl>
curl --location --request GET $page.relativePath.split('/')[1].split('.md')[0]

</template>
<CodeSwitcher>
ssuess commented 2 years ago

well I figured it out partially, I can do this:

<pre><code>curl --location --request GET {{$page.relativePath.split('/')[1].split('.md')[0]}}</code></pre>

but then I lose my prism highlighting

padarom commented 2 years ago

This seems related to https://github.com/vuejs/vuepress/issues/413. The issue I see is that if the code can change, then so needs its highlighting. The highlighting does not seem to be reactive though.

That's why for interpolated <code> blocks the syntax highlighting is disabled.

Crafting a solution for this unfortunately is outside the scope of this plugin.