Détail du package

@mdit-vue/plugin-sfc

mdit-vue134.7kMIT3.0.2

A markdown-it plugin to help transforming markdown to vue sfc

markdown-it, markdown-it-plugin, vue, sfc

readme

@mdit-vue/plugin-sfc

npm license

A markdown-it plugin to help transforming markdown to Vue SFC.

  • Avoids rendering <script> and <style> tags and extract them into to markdown-it env.sfcBlocks.
  • Supports extracting custom blocks.
  • Provides env.sfcBlocks.template for convenience.

Install

npm i @mdit-vue/plugin-sfc

Usage

This plugin will only take effects when the html option of markdown-it is enabled:

import { sfcPlugin } from '@mdit-vue/plugin-sfc';
import type { MarkdownItEnv } from '@mdit-vue/types';
import MarkdownIt from 'markdown-it';

const md = MarkdownIt({ html: true }).use(sfcPlugin, {
  // options
});
const env: MarkdownItEnv = {};

const rendered = md.render(
  `\
# foo

<script>
console.log('bar')
</script>
`,
  env,
);

console.log(env.sfcBlocks);

Options

customBlocks

  • Type: string[]

  • Default: []

  • Details:

    SFC custom blocks to be extracted.

    By default, only <script> and <style> tags will be extracted. You can set this option to support SFC custom blocks in markdown.

    For example, if you set this option to ['i18n'], the <i18n> tag in your markdown content will be extracted to env.sfcBlocks.customBlocks and won't appear in the rendered result.

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

3.0.2 (2025-08-11)

Bug Fixes

  • plugin-title: avoid output types being tree-shaken (6255fd4)

3.0.1 (2025-08-11)

Note: Version bump only for package @mdit-vue/monorepo

3.0.0 (2025-08-11)

Build System

BREAKING CHANGES

  • drop node 18 and migrate to pure ESM packages

2.1.4 (2025-04-10)

Bug Fixes

  • plugin-frontmatter: extract frontmatter in parse step (close #13) (#14) (1192bd2)

2.1.3 (2024-05-13)

Note: Version bump only for package @mdit-vue/monorepo

2.1.2 (2024-04-15)

Bug Fixes

  • sync markdown-it types updates (#9) (f6768b1)

2.1.1 (2024-04-13)

Bug Fixes

  • plugin-component: inline html block tags to make cjs build work (eb1a264)

2.1.0 (2024-04-08)

Features

  • upgrade markdown-it types to v14 (6839be8)

2.0.0 (2023-12-08)

Features

BREAKING CHANGES

  • bump to markdown-it 14

1.0.0 (2023-09-26)

Bug Fixes

  • plugin-toc: remove duplicate itemClass (#7) (7e0f1f0)

BREAKING CHANGES

  • drop support for node 16

0.12.1 (2023-08-24)

Note: Version bump only for package mdit-vue

0.12.0 (2023-02-10)

Features

  • plugin-headers: add shouldAllowNested option (93e004d)
  • plugin-toc: add shouldAllowNested option (close #5) (1f3b867)
  • shared: add shouldAllowNested option for resolveHeadersFromTokens (9363b92)

0.11.2 (2022-12-23)

Bug Fixes

  • shared: avoid resolve headers in nested blocks (ce146bd)

0.11.1 (2022-08-30)

Note: Version bump only for package mdit-vue

0.11.0 (2022-08-25)

Features

  • plugin-sfc: extract all script blocks (8c39df6)

0.10.0 (2022-08-23)

Features

  • plugin-headers: resolve link property for headers (da2954f)
  • types: add link property to header (7461417)

0.9.4 (2022-08-23)

Bug Fixes

  • plugin-component: handle multiline component tags correctly (53724fa)

0.9.3 (2022-08-20)

Bug Fixes

  • plugin-headers: avoid headers being overridden by another rendering (de1030b)
  • plugin-title: avoid title being overridden by another rendering (43cc020)

0.9.2 (2022-08-18)

Bug Fixes

  • plugin-toc: avoid toc being overridden by another rendering (c145c26)

0.9.1 (2022-07-26)

Bug Fixes

  • plugin-sfc: expose MarkdownSfcBlocks type (c2a91de)

0.9.0 (2022-07-26)

Features

  • plugin-sfc: extract SFC blocks as structured data (5a0aa54)

BREAKING CHANGES

  • plugin-sfc: the type of env.sfcBlocks has been changed

0.8.1 (2022-07-22)

Bug Fixes

  • plugin-component: make component tags behave like inline tags in some cases (9db6f9c)

0.8.0 (2022-07-22)

Features

  • plugin-component: add blockTags and inlineTags options (4651422)

0.7.1 (2022-07-20)

Note: Version bump only for package mdit-vue

0.7.0 (2022-07-18)

Features

  • plugin-frontmatter: extract content without frontmatter into env.content (a9d5cef)

0.6.0 (2022-07-11)

Features

  • types: extract types from shared package (5fc56ce)

0.5.0 (2022-07-06)

Features

  • plugin-frontmatter: add frontmatter plugin (bcffc7a)

0.4.0 (2022-07-02)

Features

  • plugin-headers: add headers plugin (636aa9b)
  • plugin-title: add title plugin (662e153)

0.3.1 (2022-06-25)

Bug Fixes

  • plugin-toc: export types (310320e)

0.3.0 (2022-06-25)

Features

  • plugin-toc: add toc plugin (e64cc2c)
  • shared: add html escape and unescape utils (e1103c2)

0.2.0 (2022-06-23)

Features

  • plugin-sfc: add sfc plugin (1eb4e0a)
  • shared: add shared package (9e36bdc)

0.1.1 (2022-06-23)

Bug Fixes

  • plugin-component: add js extension to work with esm (42ccdad)

0.1.0 (2022-06-22)

Features

  • plugin-component: add component plugin (cd2eeaa)