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

[Documentation] Change markdown-it options "on the fly" while using $md.render #57

Open
Nabellaleen opened this issue May 13, 2022 · 0 comments

Comments

@Nabellaleen
Copy link

To use specific options "on the fly", you can proceed by altering temporary, the $md.options flags.

Note : usage of $md.render require the usage of markdownit: { runtime: true } in nuxt.config.js

<template>
  <!-- eslint-disable-next-line vue/no-v-html -->
  <div v-html="rendered" />
</template>

<script>
export default {
  props: {
    markdown: { type: String, required: true },
    options: { type: Object, default: null },
  },
  computed: {
    rendered() {
      const md = this.$md;
      let backupOptions;
      if (this.options) {
        // Backup initial preset
        backupOptions = Object.assign({}, md.options);
        // Overrides options with props ones
        Object.assign(md.options, this.options);
      }
      // Render
      const rendered = md.render(this.markdown);
      if (this.options) {
        // Restore backuped options
        md.options = backupOptions;
      }
      return rendered
    },
  },
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant