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

snippet plugin root params Missing default value #204

Merged
merged 3 commits into from
Feb 10, 2021

Conversation

hcg1023
Copy link
Contributor

@hcg1023 hcg1023 commented Jan 13, 2021

No description provided.

@yyx990803
Copy link
Member

Why does it need this? Making it optional makes it possible for other parts of the codebase to forget it and lead to potential errors.

@hcg1023
Copy link
Contributor Author

hcg1023 commented Jan 14, 2021

Why does it need this? Making it optional makes it possible for other parts of the codebase to forget it and lead to potential errors.

Now introducing a block of code in Markdown using the @ sign will result in undefined, and when Markdown-it uses SnippetPlugin, no parameters are defined, so provide a default value to keep its behavior consistent with VuePress

@yyx990803
Copy link
Member

What kind of markdown causes this problem? I'd help to at least have an example. When submitting PRs, it's better to provide enough context upfront since we don't necessarily know what problem you are actually dealing with.

@hcg1023
Copy link
Contributor Author

hcg1023 commented Jan 15, 2021

What kind of markdown causes this problem? I'd help to at least have an example. When submitting PRs, it's better to provide enough context upfront since we don't necessarily know what problem you are actually dealing with.

I'm sorry, this is a case where I had a problem:
https://github.com/hcg1023/vitepress-bug

@kiaking
Copy link
Member

kiaking commented Feb 10, 2021

Oh OK now I see the problem. So snippetPlugin is never getting the 2nd argument root because it's not passed from anywhere. So instead of setting the default value to the argument, I think we should pass down the root value from the createMarkdownToVueRenderFn in markdownToVue.ts.

export function createMarkdownToVueRenderFn(
  root: string,
  options: MarkdownOptions = {}
) {
  const md = createMarkdownRenderer(options, root) // <- pass root

  ...
export const createMarkdownRenderer = (
  root: string, // <- add
  options: MarkdownOptions = {}
): MarkdownRenderer => {
  const md = MarkdownIt({
    html: true,
    linkify: true,
    highlight,
    ...options
  })

  // custom plugins
  md.use(componentPlugin)
    ...
    .use(snippetPlugin, root) // <- pass in root
    ...

@hcg1023 Would you like to update the PR?

@kiaking kiaking added the bug Something isn't working label Feb 10, 2021
hcg1023 added a commit to hcg1023/vitepress that referenced this pull request Feb 10, 2021
@hcg1023
Copy link
Contributor Author

hcg1023 commented Feb 10, 2021

createMarkdownToVueRenderFn

yes

Oh OK now I see the problem. So snippetPlugin is never getting the 2nd argument root because it's not passed from anywhere. So instead of setting the default value to the argument, I think we should pass down the root value from the createMarkdownToVueRenderFn in markdownToVue.ts.

export function createMarkdownToVueRenderFn(
  root: string,
  options: MarkdownOptions = {}
) {
  const md = createMarkdownRenderer(options, root) // <- pass root

  ...
export const createMarkdownRenderer = (
  root: string, // <- add
  options: MarkdownOptions = {}
): MarkdownRenderer => {
  const md = MarkdownIt({
    html: true,
    linkify: true,
    highlight,
    ...options
  })

  // custom plugins
  md.use(componentPlugin)
    ...
    .use(snippetPlugin, root) // <- pass in root
    ...

@hcg1023 Would you like to update the PR?

Yes, I have updated my Commit

Copy link
Member

@kiaking kiaking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update and finding the issue! 🙌

@kiaking kiaking merged commit 2aa8ab2 into vuejs:master Feb 10, 2021
@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
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants