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

doc: add options overriding example on $md.render documentation #58

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,42 @@ export default {
</script>

```

#### Overriding temporarily markdown-it options

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

`hello.vue`:
```html
<template>
<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>
```