Skip to content

Expose the built-in markdown parser to render markdown-valued variables with #2410

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

Open
4 tasks done
aentwist opened this issue May 25, 2023 · 4 comments
Open
4 tasks done
Labels

Comments

@aentwist
Copy link

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

My CMS stores markdown values in frontmatter data. For example, an intro section intro with a markdown string value. Currently, trying to access it in the page with {{ $frontmatter.intro }} just renders it as a string (a direct result of the markdown -> Vue -> HTML pipeline). What is the recommended way to call the markdown parser on it?

Describe the solution you'd like

It would be nice to see this exposed somehow (getting the built-in markdown-it instance, for example).

Describe alternatives you've considered

I could install markdown-it separately and use it that way?

Additional context

No response

Validations

@aentwist
Copy link
Author

Well, it just occurred to me that this use case is probably unusual... so allow me to elaborate.

I want to build a landing page and allow non-technical users to edit specific content (potentially using rich text I guess?) without being exposed to the structure.

My strategy is to use a custom theme that makes use of frontmatter keys to "slot in" content into specific places in the page instead of allowing the whole page to be edited with the CMS's special "body" frontmatter field (that makes up the non-frontmatter, or main, markdown content for pages).

@github-actions github-actions bot added the stale label Aug 3, 2023
@MetRonnie
Copy link

This would be really handy. My use case is to auto-document an API - long story short I have a script that outputs a markdown snippet from Python source code, and I am loading this into a page.

// foo.data.js
import { execSync } from 'child_process'

export default {
  load: () => execSync('python3 ./script-that-outputs-md.py').toString()
}
<!-- page.md -->
<script setup>
import { data } from './foo.data.js'
</script>

# My API

{{ data }}

This just renders the markdown snippet as an unformatted string.

However I was able to figure out by poking about the vitepress source code that you can use an undocumented function called createMarkdownRenderer():

// foo.data.js
import { execSync } from 'child_process'
import { createMarkdownRenderer } from 'vitepress'

export default {
  load: async () => {
    const md = await createMarkdownRenderer('')
    return md.render(
      execSync('python3 ./script-that-outputs-md.py').toString()
    )
  }
}
 <!-- page.md -->
 # My API

-{{ data }}
+<div v-html="data"></div>

I think this ought to be straightforward to expose in a more user-friendly and documented way?

@Aganivi
Copy link

Aganivi commented Dec 18, 2023

createMarkdownRenderer don't seem to work?

@github-actions github-actions bot removed the stale label Dec 26, 2023
@github-actions github-actions bot added the stale label Feb 2, 2024
@Marhc
Copy link

Marhc commented Apr 26, 2025

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants