vuejs / vitepress

Vite & Vue powered static site generator.
https://vitepress.dev
MIT License
11.93k stars 1.93k forks source link

[markdown-it] as a pluggable markdown parser #3347

Open RSS1102 opened 6 months ago

RSS1102 commented 6 months ago

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

I used an sever API that can convert *.md strings into HTML elements. I want it to replace the parsing of markdown-it .Display the parsed markup content on the page.

Describe the solution you'd like

Can markdown-it serve as a pluggable markdown parser? can be replaced with other markup parsers.

Describe alternatives you've considered

Alternatively, have a hook from the *.md string to the page content using an API, and skip the parsing of the markdown-it.

Additional context

No response

Validations

brc-dd commented 6 months ago

You can do something like this:

// .vitepress/config.ts

import { defineConfig } from 'vitepress'

export default defineConfig({
  markdown: {
    config(md) {
      md.render = function (src, env) {
        return yourRenderer(src, env) // return html string from here, you'll need to set some stuff in env too
      }
    }
  }
})

Will this be sufficient for you? Or can you explain in bit detail what you're trying to do?