Skip to content

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

@NtchPlayer

Description

@NtchPlayer

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions