Skip to content

Instantly share code, notes, and snippets.

@b4n92uid
Last active August 17, 2021 22:17
Show Gist options
  • Save b4n92uid/46067f8cbc12c493481e37d41bc7e7ad to your computer and use it in GitHub Desktop.
Save b4n92uid/46067f8cbc12c493481e37d41bc7e7ad to your computer and use it in GitHub Desktop.
[Vue] MarkdownPlugin
import MarkdownIt from "markdown-it";
const markdown = new MarkdownIt({
breaks: true,
xhtmlOut: true
});
export default {
install(Vue) {
Vue.filter("markdown", function(text) {
return markdown.renderInline(text);
});
Vue.directive("markdown", {
inserted(el) {
el.innerHTML = markdown.renderInline(el.innerText);
}
});
Vue.mixin({
methods: {
formatMarkdown(str) {
return markdown.renderInline(str);
}
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment