-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Comments
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). |
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 // 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? |
createMarkdownRenderer don't seem to work? |
+1 |
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
The text was updated successfully, but these errors were encountered: