Last active
August 17, 2021 22:17
-
-
Save b4n92uid/46067f8cbc12c493481e37d41bc7e7ad to your computer and use it in GitHub Desktop.
[Vue] MarkdownPlugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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