Giter Club home page Giter Club logo

vite-plugin-markdoc-vue's Introduction

vite-plugin-markdoc-vue

A plugin that enables you to import Markdoc extended markdowns as Vue components.

Installation

Install the renderer and plugin:

pnpm add @markdoc/markdoc vite-plugin-markdoc-vue -D

TypeScript Shim

where needed:

declare module '*.vue' {
  import type { ComponentOptions } from 'vue'

  const Component: ComponentOptions
  export default Component
}

declare module '*.md' {
  import type { ComponentOptions } from 'vue'

  const Component: ComponentOptions
  export default Component
}

then add the following to vite.config.ts

import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue'
import MarkdocVue from 'vite-plugin-markdoc-vue'

export default defineConfig({
  plugins: [
    Vue({
      include: [/\.vue$/, /\.md$/], // <--
    }),
    MarkdocVue(),
  ]
})

And import it as a normal Vue component.

Import Markdown as Vue components

<script setup>
import Content from './content.md'
</script>

<template>
  <Content />
</template>

Render Vue components

Imported markdown files accepts an optional components object as a prop. The components object specifies a mapping from your tags and nodes to the corresponding Vue component.

First, add your transformation options to the plugin:

const tags = {
  callout: {
    render: 'Callout',
    attributes: {}
  }
}

export default defineConfig({
  plugins: [
    Vue({
      include: [/\.vue$/, /\.md$/], // <--
    }),
    MarkdocVue({
      tags
    }),
  ]
})

Then pass your custom component:

{% callout %}
Attention, over here!
{% /callout %}
<script setup>
import Content from './content.md'
import Callout from './Callout.vue'
</script>

<template>
  <Content :components="{ Callout }" />
</template>
<template>
  <div class="callout">
    <slot />
  </div>
</template>

<style>
.callout {}
</style>

This renders to:

<article>
  <div class="callout">
    <p>Attention, over here!</p>
  </div>
</article>

Configuration

The plugin accepts an optional Markdoc.transform config:

// vite.config.ts
export default defineConfig({
  plugins: [
    Vue({
      include: [/\.vue$/, /\.md$/], // <--
    }),
    MarkdocVue({
      nodes: {},
      tags: {}
    }),
  ]
})

Related

License

MIT

vite-plugin-markdoc-vue's People

Contributors

wobsoriano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

fahimekhandan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.