Skip to content

Can't get correct interpolation for codeblock in markdown #512

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

Closed
avishnyakov opened this issue May 27, 2018 · 2 comments
Closed

Can't get correct interpolation for codeblock in markdown #512

avishnyakov opened this issue May 27, 2018 · 2 comments

Comments

@avishnyakov
Copy link

avishnyakov commented May 27, 2018

Bug report

Can't get correct interpolation for codeblock in markdown. Followed approach with custom Vue component to inject markdown content via slot described below:

That works well for inline markdown within a Vue component. However, does not seem to work if interpolation is used within markdown codeblock. That prevents rendering source code which is stored elsewhere outside of markdown pages - metadata, front matter or external files.

MarkdownInVue.vue

<template>
  <div>
    <slot></slot>
  </div>
</template>

Then using directive over JSON data:

{
    "samples": [
        {
            "title":"sample1",
            "description": "descriptoin 1",
            "code": "\nvar i = 1;\n"
        },
         {
            "title":"sample2",
            "description": "descriptoin 2",
            "code": "\nvar i = 2;\n"
        }
    ] 
}

Later my markdown file:

// just preloaded mentioned JSON into themeConfig.samples variable
<div v-for="(item, index) in this.$site.themeConfig.samples">
{{ item.title }} with source code:

<MarkdownInVue>

  ## {{ item.title  }}
  {{ item.description }}

  \~~~~ 
  {{ item.code }} 
  \~~~~ 

  \```
  {{ item.code }} 
  \```

</MarkdownInVue>

</div>

Outcome:

image

Version

0.10.0

Steps to reproduce

As per setup early

What is expected?

Either of these:

  1. VuePress allows interpolation within codeblock in markdown so that the source code can be rendered dynamically.
  2. VuePress provides means to render source code from variable (which is stored elsewhere outside of markdown pages - metadata, front matter or external file)

What is actually happening?

VuePress skips interpolation for markdown codeblock.

Other relevant information

  • Your OS: Windows
  • Node.js version: v9.5.0
  • Is this a global or local install? - Global
  • Which package manager did you use for the install? - npm
@ulivz
Copy link
Member

ulivz commented May 27, 2018

Let's see your usage:

// just preloaded mentioned JSON into themeConfig.samples variable
<div v-for="(item, index) in this.$site.themeConfig.samples">
{{ item.title }} with source code:

<MarkdownInVue>

  ## {{ item.title  }}
  {{ item.description }}

  \~~~~ 
  {{ item.code }} 
  \~~~~ 

  \```
  {{ item.code }} 
  \```

</MarkdownInVue>

</div>

You may not understand how vuepress works, you are generating markdown at runtime...

Although we can support interpolation in code block, BUT your usage is INVALID.

Closing it since it is duplicate of #413 / #415.

@ulivz ulivz closed this as completed May 27, 2018
@avishnyakov
Copy link
Author

@ulivz, thanks for spending some time on this, appreciate that.

Not sure how #413 / #415 can help to get a bunch of source code stored in a variable rendered nicely.

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