Skip to content

JSFiddle

npm versionnpm monthly downloadsnpm sizenpm license

Embed JSFiddle projects into VitePress pages.

Installation

sh
pnpm add vitepress-plugin-jsfiddle
sh
npm install vitepress-plugin-jsfiddle
sh
bun add vitepress-plugin-jsfiddle
sh
deno add vitepress-plugin-jsfiddle
sh
yarn add vitepress-plugin-jsfiddle

Usage

.vitepress/config.ts
ts
import { defineConfig } from 'vitepress-tuck'
import jsfiddle from 'vitepress-plugin-jsfiddle'

export default defineConfig({
  plugins: [jsfiddle()],
})

Learn more about vitepress-tuck

Native Mode

.vitepress/config.ts
ts
import { defineConfig } from 'vitepress'
import { jsfiddleMarkdownPlugin } from 'vitepress-plugin-jsfiddle'

export default defineConfig({
  markdown: {
    config: (md) => {
      md.use(jsfiddleMarkdownPlugin)
    },
  },
})
.vitepress/theme/index.ts
ts
import type { Theme } from 'vitepress'
import { enhanceAppWithJsFiddle } from 'vitepress-plugin-jsfiddle/client'
import DefaultTheme from 'vitepress/theme'

export default {
  extends: DefaultTheme,
  enhanceApp(ctx) {
    enhanceAppWithJsFiddle(ctx)
  },
} satisfies Theme

Syntax

Basic Usage

md
@[jsfiddle](user/id)

With Options

md
@[jsfiddle title="JS Fiddle" theme="dark" tab="js,css,html,result" height="400px"](pengzhanbo/1xbwz2p9)

Attribute Reference

AttributeTypeDefaultDescription
titlestring'JS Fiddle'Title
themestring-Theme (e.g. dark)
tabstring'js,css,html,result'Tabs to display (comma-separated, spaces removed)
widthstring'100%'Width
heightstring-Height
rationumber | string-Aspect ratio

Example

md
@[jsfiddle](pengzhanbo/1xbwz2p9)

Released under the MIT License