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

[Feature request] Handle template error when vueTemplate is active #52

Open
NtchPlayer opened this issue Nov 1, 2023 · 5 comments
Open

Comments

@NtchPlayer
Copy link
Contributor

NtchPlayer commented Nov 1, 2023

Clear and concise description of the problem

When we use vueTemplate, if an incorrect syntaxe is provide to the compiler, the render disappear from the page and an error is throw in the console.

You can easily reproduce it here: https://vue-showdown.js.org/playground/. Just active vueTemplate and add <mycustomelement> into the input to throw the error.

Noticed that, the error is throwing only when the project is run in production mode. In dev mode, the render don't crash and warnings are display into the console.

Suggested solution

Add a try catch to the render function. If vueTemplate can't render the let showdown render it without vueTemplate option.

// vue-showdown.ts
return () => {
  try {
    return props.vueTemplate
      ? h({
          setup: () => props.vueTemplateData,
          template: `<${props.tag}>${outputHtml.value}</${props.tag}>`,
          components: props.vueTemplateComponents,
        })
      : h(props.tag, {
          innerHTML: outputHtml.value,
        });
  } catch (renderError) {
    // Handle the exception and return only showdown render without vueTemplate
    return h(props.tag, {
      innerHTML: outputHtml.value,
    });
  }
}

Alternative

No response

Additional context

No response

@NtchPlayer NtchPlayer changed the title [Feature request] Handle error when vueTemplate is active [Feature request] Handle template error when vueTemplate is active Nov 1, 2023
@NtchPlayer
Copy link
Contributor Author

Hi !
I don't know if you have take time to see my PR to resolve this issue ? :)

@NtchPlayer
Copy link
Contributor Author

I update my PR, to solve the problem ! It's work in production 👍

@dword-design
Copy link

Any updates on this?

@NtchPlayer
Copy link
Contributor Author

Nop, I don't take time to try another fix sorry o/
If you want I publish a version of the package with the MR that a create to fix this problem. But I warn, it's not the best solution for performance. I use it for my personal project, but you can use it two if you want :)

https://www.npmjs.com/package/vue-showdown-ntchplayer

@dword-design
Copy link

Ok np I switched to @nuxtjs/mdc for now which also supports components in Markdown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants