Awesome
<!-- Improved compatibility of back to top link: See: https://github.com/othneildrew/Best-README-Template/pull/73 --><a name="readme-top"></a>
<!-- *** Thanks for checking out the Best-README-Template. If you have a suggestion *** that would make this better, please fork the repo and create a pull request *** or simply open an issue with the tag "enhancement". *** Don't forget to give the project a star! *** Thanks again! Now go create something AMAZING! :D --> <!-- PROJECT SHIELDS --> <!-- *** I'm using markdown "reference style" links for readability. *** Reference links are enclosed in brackets [ ] instead of parentheses ( ). *** See the bottom of this document for the declaration of the reference variables *** for contributors-url, forks-url, etc. This is an optional, concise syntax you may use. *** https://www.markdownguide.org/basic-syntax/#reference-style-links --> <!-- [![LinkedIn][linkedin-shield]][linkedin-url] --> <!-- PROJECT LOGO --> <br /> <div align="center"> <h1 align="center">Vue markdown-it</h1> <p align="center"> Vue 3 markdown-it component <br /> <a href="https://github.com/f3ve/vue-markdown-it"><strong>Explore the docs »</strong></a> <br /> <a href="https://github.com/f3ve/vue-markdown-it/issues">Report Bug</a> · <a href="https://github.com/f3ve/vue-markdown-it/issues">Request Feature</a> </p> </div> <!-- TABLE OF CONTENTS --> <details> <summary>Table of Contents</summary> <ol> <li> <a href="#about-the-project">About The Project</a> <ul> <li><a href="#built-with">Built With</a></li> </ul> </li> <li> <a href="#getting-started">Getting Started</a> <ul> <li><a href="#prerequisites">Prerequisites</a></li> <li><a href="#installation">Installation</a></li> </ul> </li> <li><a href="#usage">Usage</a></li> <li><a href="#roadmap">Roadmap</a></li> <li><a href="#contributing">Contributing</a></li> <li><a href="#license">License</a></li> <li><a href="#contact">Contact</a></li> <li><a href="#acknowledgments">Acknowledgments</a></li> </ol> </details> <!-- ABOUT THE PROJECT -->About The Project
This is a component for easily integrating markdown-it in Vue 3. This project was inspired by markdown-it-vue. which hasn't been updated in a while and only supports Vue 2.
<p align="right">(<a href="#readme-top">back to top</a>)</p>Built With
<p align="right">(<a href="#readme-top">back to top</a>)</p> <!-- GETTING STARTED -->Getting Started
Prerequisites
- Vue 3
npm i vue
Installation
npm i @f3ve/vue-markdown-it
<p align="right">(<a href="#readme-top">back to top</a>)</p>
<!-- USAGE EXAMPLES -->
Usage
Importing the Component
You can directly import the component in your SFC file.
In <script setup>
Syntax
<!-- Vue 3 setup script syntax -->
<script setup>
import { VueMarkdownIt } from '@f3ve/vue-markdown-it';
const post = ref();
onMounted(async () => {
const res = await api.get('/post');
post.value = res.data;
});
</script>
<template>
<vue-markdown-it :source="post" />
</template>
In Regular <script>
Syntax
<script>
import { VueMarkdownIt } from '@f3ve/vue-markdown-it';
export default {
components: {
VueMarkdownIt
}
setup() {
const post = ref();
onMounted(async () => {
const res = await api.get('/post');
post.value = res.data;
});
}
}
</script>
<template>
<vue-markdown-it :source="post" />
</template>
Using the Plugin
You can also use the plugin to register the component globally.
// main.js
import { createApp } from 'vue';
import App from './App.vue';
import { VueMarkdownItPlugin } from '@f3ve/vue-markdown-it';
const app = createApp(App);
app.use(VueMarkdownItPlugin);
app.mount('#app');
Using markdown-it Plugins
You can add markdown-it plugins using the plugin
prop. plugin
expects an array of markdown-it plugins. If you want to configure the options of a plugin you can nest the plugin and its options in an array.
<script setup>
import { VueMarkdownIt } from '@f3ve/vue-markdown-it';
import myPlugin from 'myPlugin';
import myPluginWithOption from 'myPluginWithOptions';
const post = ref();
onMounted(async () => {
const res = await api.get('/post');
post.value = res.data;
});
</script>
<template>
<vue-markdown-it
:source="post"
:plugins="[myPlugin, [myPluginWithOptions, { option1: true }]]"
/>
</template>
Using Markdown-it Options & Presets
See Markdown-it docs for more information
Options
Note: I'm using Vue script setup syntax in these examples. If you're not using script setup make sure to register the component before using.
<script setup>
import { VueMarkdownIt } from '@f3ve/vue-markdown-it';
const post = ref();
const options = {
html: true,
linkify: true,
};
onMounted(async () => {
const res = await api.get('/post');
post.value = res.data;
});
</script>
<template>
<vue-markdown-it :source="post" :options="options" />
</template>
Presets
<script setup>
import { VueMarkdownIt } from '@f3ve/vue-markdown-it';
const post = ref();
onMounted(async () => {
const res = await api.get('/post');
post.value = res.data;
});
</script>
<template>
<vue-markdown-it :source="post" preset="commonmark" />
</template>
Using Presets and Options together
<script setup>
import { VueMarkdownIt } from '@f3ve/vue-markdown-it';
const post = ref();
const options = {
html: true,
linkify: true,
};
onMounted(async () => {
const res = await api.get('/post');
post.value = res.data;
});
</script>
<template>
<vue-markdown-it :source="post" :options="options" preset="commonmark" />
</template>
<p align="right">(<a href="#readme-top">back to top</a>)</p>
<!-- ROADMAP -->
Roadmap
See the open issues for a full list of proposed features (and known issues).
<p align="right">(<a href="#readme-top">back to top</a>)</p> <!-- CONTRIBUTING -->Contributing
<p align="right">(<a href="#readme-top">back to top</a>)</p> <!-- LICENSE -->License
Distributed under the MIT License.
<p align="right">(<a href="#readme-top">back to top</a>)</p> <!-- MARKDOWN LINKS & IMAGES --> <!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->