vitepress icon indicating copy to clipboard operation
vitepress copied to clipboard

Multi region snippet support

Open ciscoo opened this issue 1 year ago • 1 comments
trafficstars

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

Only a single region in a code snippet is supported.

Here is a sample demonstrating the issue: https://stackblitz.com/edit/vite-2wp1zt?file=docs%2Fexample.md

Describe the solution you'd like

I would like to be able to do the following:

// #region snippet
import io.mateo.cxf.codegen.wsdl2java.Wsdl2Java
// #endregion snippet

plugins {
    id "java"
    id "io.mateo.cxf-codegen"
}

// #region snippet

// ...

tasks.register("example", Wsdl2Java) {
    toolOptions { // <2>
        wsdl.set(file("path/to/example.wsdl").toPath().toAbsolutePath().toString())
    }
    allJvmArgs = ["-Duser.language=fr", "-Duser.country=CA"]
}
// #endregion snippet

tasks.register("verify") {
    doLast {
        println tasks.getByName("example").wsdl2JavaOptions.wsdl.get()
    }
}

Which would render as:

import io.mateo.cxf.codegen.wsdl2java.Wsdl2Java

// ...

tasks.register("example", Wsdl2Java) {
    toolOptions { // <2>
        wsdl.set(file("path/to/example.wsdl").toPath().toAbsolutePath().toString())
    }
    allJvmArgs = ["-Duser.language=fr", "-Duser.country=CA"]
}

Describe alternatives you've considered

No response

Additional context

I'm working on migrating my project's documentation to VitePress from Asciidoctor which has support for multiple tagged regions

Validations

ciscoo avatar Mar 23 '24 01:03 ciscoo

You can use this plugin - https://github.com/fabioaanthony/markdown-it-vuepress-code-snippet-enhanced

example:

// #foo
import { defineConfig } from 'vitepress'
import snippetPlugin from 'markdown-it-vuepress-code-snippet-enhanced'
// #foo

export default defineConfig({
  markdown: {
    // #foo
    config(md) {
      md.use(snippetPlugin)
    }
    // #foo
  }
})

usage:

@[code transcludeWith=#foo](@/path/to/file)

brc-dd avatar Apr 12 '24 06:04 brc-dd