Skip to content

Field ​

npm versionnpm monthly downloadsnpm sizenpm license

Field container plugin for rendering structured API fields and properties documentation in Markdown, with support for JSDoc-style tag annotations and field grouping.

Installation ​

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

Usage ​

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

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

Learn more about vitepress-tuck

Native Mode ​

.vitepress/config.ts
ts
import { defineConfig } from 'vitepress'
import { fieldMarkdownPlugin, fieldVitePlugin } from 'vitepress-plugin-field'

export default defineConfig({
  markdown: {
    config: (md) => {
      md.use(fieldMarkdownPlugin)
    },
  },
  vite: {
    plugins: [fieldVitePlugin(/* options */)],
  },
})
.vitepress/theme/index.ts
ts
import type { Theme } from 'vitepress'
import { enhanceAppWithField } from 'vitepress-plugin-field/client'
import DefaultTheme from 'vitepress/theme'

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

Syntax ​

Use the ::: field container to document fields and properties: the text after ::: field on the opening line is the field name, while the container body uses JSDoc-style tags to describe field metadata. Any non-tag line is treated as the field description.

Basic Field ​

md
::: field count
@type Number
@default 0
Total number of users.
:::

Rendered Result:

Name:count​

Optional

Type:Number

Default:0

Total number of users.

Tag Reference ​

TagValueDescription
@namestringOverride the field name (defaults to the name from info)
@typestringField type annotation
@typeLinkstringType reference link, rendered as a clickable link
@defaultstringDefault value for the field
@requiredflagMark the field as required
@deprecatedflag / stringMark the field as deprecated, optionally with a version or date
@experimentalflag / stringMark the field as experimental, optionally with a version or date
@descriptionstringExplicit description text; any non-tag line also becomes description
@enumstringCandidate values separated by |, appended across lines
@sincestringVersion the field was introduced in; only the first value is kept
@unitstringUnit annotation
@formatstringFormat annotation
@constraintstringConstraint annotation
@optional—Deprecated, no longer parsed (fields are optional by default)

@name — Override the Field Name ​

The info on the opening line is used as the field name by default; @name overrides it:

md
::: field rawName
@name userName
@type String
Unique identifier for the user.
:::

Rendered Result:

Name:userName​

Optional

Type:String

Unique identifier for the user.

@type declares the field type, and @typeLink provides a reference link for it:

md
::: field options
@type Record<string, unknown>
@typeLink /plugins/field
Configuration options.
:::

Rendered Result:

Name:options​

Optional

Configuration options.

@default — Default Value ​

md
::: field createdAt
@type Date
@default Date.now()
Creation timestamp.
:::

Rendered Result:

Name:createdAt​

Optional

Type:Date

Default:Date.now()

Creation timestamp.

@required — Required Field ​

A boolean flag; any value after it is ignored (@required yes is equivalent to @required):

md
::: field id
@type Number
@required
Unique identifier.
:::

Rendered Result:

Name:id​

Required

Type:Number

Unique identifier.

@deprecated — Deprecated Field ​

Used alone it is a boolean flag; with a value it describes the version or date of deprecation:

md
::: field legacy
@type String
@deprecated
This field is deprecated.
:::
md
::: field oldField
@type String
@deprecated v2.0
Deprecated in v2.0, please use `newField` instead.
:::

Rendered Result:

Name:legacy​

Deprecated

Type:String

This field is deprecated.

Name:oldField​

Deprecated: v2.0

Type:String

Deprecated in v2.0, please use newField instead.

@experimental — Experimental Field ​

Similar to @deprecated: it is a boolean flag when used alone, and may carry the version or date it was introduced in:

md
::: field stream
@type Boolean
@experimental v3.0
Experimental capability; the API may change.
:::

Rendered Result:

Name:stream​

OptionalExperimental: v3.0

Type:Boolean

Experimental capability; the API may change.

@description — Explicit Description ​

Declare the description text explicitly; non-tag lines are also treated as description and can be mixed with @description:

md
::: field count
@description Total number of users. This field represents the count of active users in the system.
@type Number
@default 0
:::

Rendered Result:

Name:count​

Optional

Type:Number

Default:0

Total number of users. This field represents the count of active users in the system.

@enum — Candidate Values ​

Separate candidate values with |; surrounding whitespace is trimmed and quotes are preserved:

md
::: field status
@type String
@default active
@enum active | inactive | pending
:::

Multiple @enum lines are appended to the same set of candidates:

md
::: field level
@type Number
@enum 1 | 2
@enum 3
:::

Rendered Result:

Name:status​

Optional

Type:String

Default:active

Allowed values:activeinactivepending

Name:level​

Optional

Type:Number

Allowed values:123

@since — Version Introduced ​

Only the first value is kept:

md
::: field pageSize
@type Number
@since 1.2.0
Page size.
:::

Rendered Result:

Name:pageSize​

Optional

Type:Number
Since:1.2.0

Page size.

@unit, @format and @constraint — Unit, Format and Constraint ​

md
::: field timeout
@type Number
@default 3000
@unit ms
@constraint 1..60000
Timeout in milliseconds.
:::

::: field date
@type String
@format YYYY-MM-DD
Date string.
:::

Rendered Result:

Name:timeout​

Optional

Type:Number

Default:3000

Unit:ms

Constraint:1..60000

Timeout in milliseconds.

Name:date​

Optional

Type:String

Format:YYYY-MM-DD

Date string.

Combined Usage ​

Tags can be freely combined:

md
::: field pageSize
@type Number
@typeLink /plugins/field
@required
@default 20
@unit items
@constraint 1..100
@since 1.2.0
@experimental v2.0
Number of records returned per page when paginating.
:::

Rendered Result:

Name:pageSize​

RequiredExperimental: v2.0

Type:Number

Default:20

Unit:items

Constraint:1..100

Since:1.2.0

Number of records returned per page when paginating.

Field Group ​

Use the ::: field-group container to group related fields together:

md
:::: field-group

::: field id
@type Number
@required
Unique identifier.
:::

::: field name
@type String
Display name.
:::

::: field createdAt
@type Date
@default Date.now()
Creation timestamp.
:::

::::

Rendered Result:

Name:id​

Required

Type:Number

Unique identifier.

Name:name​

Optional

Type:String

Display name.

Name:createdAt​

Optional

Type:Date

Default:Date.now()

Creation timestamp.

Parsing Rules ​

  • A tag must occupy its own line and start with @; only one tag is parsed per line. Lines that do not start with @ are treated as description text.
  • Tag names are case-insensitive: @Type is equivalent to @type.
  • Surrounding backticks are removed from tag values: @type `String` is equivalent to @type String.
  • Tags without a value are ignored (except boolean flags such as @required and @deprecated).
  • When a scalar tag is repeated the last value wins (e.g. @name, @type, @default); @enum appends values; @since keeps only the first.
  • Unknown tags (e.g. @author) are kept as description text and do not interrupt the current description paragraph.
  • Blank lines do not interrupt a description paragraph; they are preserved as line breaks in the description.
  • Fields with the same name on the same page get unique anchors automatically: field-<name>, field-<name>-1, field-<name>-2…

Released under the MIT License