Skip to content
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

Expose __path and __relativePath options on md instance for md plugins #1258

Closed
4 tasks done
flingyp opened this issue Aug 30, 2022 · 7 comments
Closed
4 tasks done

Comments

@flingyp
Copy link

flingyp commented Aug 30, 2022

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

I found that #1240 has removed these two parameters, which makes it impossible for me to customize the MD plugin on this basis

Describe the solution you'd like

Can you __ Path and __ Relativepath these two attributes are added to the MD instance to better customize the MD plugin

Describe alternatives you've considered

No response

Additional context

No response

Validations

@brc-dd
Copy link
Member

brc-dd commented Aug 30, 2022

They were not removed, they were moved to env.

@meteorlxy
Copy link
Member

FYI:

An env sandbox can be used alongside tokens to inject external variables for your parsers and renderers.

export interface MarkdownEnv extends MarkdownItEnv {
path: string
relativePath: string
cleanUrls: CleanUrlsMode
links?: string[]
}

@meteorlxy
Copy link
Member

Just noticed that MarkdownEnv type did not get exposed. See #1259

@flingyp
Copy link
Author

flingyp commented Aug 30, 2022

@meteorlxy I see __ data. Hoistedtags has also been deleted. If I need to add a script setup script code to the MD file to introduce my components. I should report to env.sfcBlocks.customBlocks insert script?

@meteorlxy
Copy link
Member

meteorlxy commented Aug 30, 2022

env.sfcBlocks.scriptSetup would help.

See https://github.com/mdit-vue/mdit-vue/blob/main/packages/plugin-sfc/src/types.ts#L43-L76

@flingyp
Copy link
Author

flingyp commented Aug 30, 2022

@meteorlxy

I finally used env.sfcblocks.scripts because vitepress does not seem to handle 'env.sfcblocks.scriptsetup` code logic. But thank you for guiding me to solve the problem.

const vueSrc = [
    ...injectPageDataCode(
      sfcBlocks?.scripts.map((item) => item.content) ?? [],
      pageData,
      replaceRegex
    ),
    `<template><div>${replaceConstants(
      html,
      replaceRegex,
      vueTemplateBreaker
    )}</div></template>`,
    ...(sfcBlocks?.styles.map((item) => item.content) ?? []),
    ...(sfcBlocks?.customBlocks.map((item) => item.content) ?? [])
  ].join('\n')

@meteorlxy
Copy link
Member

Uh yes, I forgot that.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants