@f3ve/vue-markdown-it

中文文档
0.2.3发布于 2024/10/27MITTypeScriptESM + CJS近 30 天下载 6876

Vue 3 markdown-it component

原始使用文档
文档目录13 节
  1. About The Project
  2. Built With
  3. Getting Started
  4. Prerequisites
  5. Installation
  6. Usage
  7. Importing the Component
  8. Using the Plugin
  9. Using markdown-it Plugins
  10. Using Markdown-it Options & Presets
  11. Roadmap
  12. Contributing
  13. License

Contributors Forks Stargazers Issues MIT License


Vue markdown-it

Vue 3 markdown-it component
Explore the docs »
Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

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.

(back to top)

Built With

  • Vue
  • Vite

(back to top)

Getting Started

Prerequisites

  • Vue 3
npm i vue

Installation

npm i @f3ve/vue-markdown-it

(back to top)

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 setup>
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>

(back to top)

Roadmap

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

See contributing guide

(back to top)

License

Distributed under the MIT License.

(back to top)

版本与发布记录

@f3ve/vue-markdown-it 共发布 6 个版本,首次发布于 2023/09/14;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.2.3latest2024/10/272 年前
0.2.22024/04/142 年前
0.2.02023/10/053 年前
0.1.22023/10/053 年前
0.1.12023/09/143 年前
0.1.02023/09/143 年前

关于 @f3ve/vue-markdown-it 的常见问题

@f3ve/vue-markdown-it 是什么?

Vue 3 markdown-it component

如何安装 @f3ve/vue-markdown-it?

在项目目录运行 npm install @f3ve/vue-markdown-it,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vue(^3.3.4)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@f3ve/vue-markdown-it 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@f3ve/vue-markdown-it 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@f3ve/vue-markdown-it 可以商用吗?

@f3ve/vue-markdown-it 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@f3ve/vue-markdown-it 的下载量有多少?

根据 npm 官方下载统计,@f3ve/vue-markdown-it 在 2026/10/14 – 2026/11/12 这 30 天内被下载 6,876 次,日均约 229 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@f3ve/vue-markdown-it 还在维护吗?

最新版本 0.2.3 发布于 2024/10/27(2 年前);至今共发布 6 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/09/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。