Skip to content

async transforms between parse and render call #62

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
3 tasks done
s-light opened this issue Mar 4, 2025 · 0 comments · May be fixed by #63
Open
3 tasks done

async transforms between parse and render call #62

s-light opened this issue Mar 4, 2025 · 0 comments · May be fixed by #63
Labels
enhancement New feature or request

Comments

@s-light
Copy link

s-light commented Mar 4, 2025

Clear and concise description of the problem

i would like to embed code from files into fenced blocks:

for this i need some async action:
markdown-it/markdown-it#256 (comment)

i need to call my transform function on the parsed tokens array -
and then call the render function.

so would be super nice to be able to just insert async transformative calls between the two tasks..
something like:

const tokens = md.parse(your_source_md, env);
// run async function with only side-effects on tokens
await callAsyncFN(tokens, idx, options, env, sefl);
return md.renderer.render(tokens, md.options, env);

as fare as i can tell this would also mean an addition to the markdown-it-async wrapper.
(as there is only the full render call available at this..)

Suggested solution

add option similar to this
types.ts

// ...
/**
   * Custom tranformations apply before and after the markdown transformation
   */
  transforms?: {
    before?: (code: string, id: string) => string | Promise<string>
    renderingAfterParsingBeforeRender?: (tokens: array, idx: number, options: object, env: object, self:MarkdownIt) => None  | Promise<none>
    after?: (code: string, id: string) => string | Promise<string>
    /**
     * Return extra code to be injected into the `<script>` tag
     */
    extraScripts?: (frontmatter: Record<string, any>, id: string) => string[] | Promise<string[]>
  }
// ...

Alternative

No response

Additional context

i will try and create some sort of minimal example in the next days

for a complex test-setup you can have a look at
https://github.com/s-light/quasar-unplugin-vue-markdown-tests
https://codesandbox.io/p/github/s-light/quasar-unplugin-vue-markdown-tests/

Validations

@s-light s-light added the enhancement New feature or request label Mar 4, 2025
@s-light s-light changed the title async plugin → async transforms between parse and render call async transforms between parse and render call Mar 4, 2025
s-light added a commit to s-light/unplugin-vue-markdown that referenced this issue Mar 5, 2025
@s-light s-light linked a pull request Mar 5, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant