|
| 1 | +--- |
| 2 | +icon: list-checks |
| 3 | +--- |
| 4 | + |
| 5 | +# markdown-field |
| 6 | + |
| 7 | +<NpmBadge package="@vuepress/plugin-markdown-field" /> |
| 8 | + |
| 9 | +Add fields to your VuePress site. |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +```bash |
| 14 | +npm i -D @vuepress/plugin-markdown-field@next |
| 15 | +``` |
| 16 | + |
| 17 | +```ts title=".vuepress/config.ts" |
| 18 | +import { markdownFieldPlugin } from '@vuepress/plugin-markdown-field' |
| 19 | + |
| 20 | +export default { |
| 21 | + plugins: [ |
| 22 | + markdownFieldPlugin({ |
| 23 | + // Enable fields |
| 24 | + fields: true, |
| 25 | + }), |
| 26 | + ], |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +## Syntax |
| 31 | + |
| 32 | +You can use `::: fields` container to describe field information, including field name, type, whether it's required, default value, etc. |
| 33 | + |
| 34 | +Inside the container, lines starting with `@name@` are field items. Attributes are appended after the closing `@`. |
| 35 | + |
| 36 | +```md |
| 37 | +::: fields |
| 38 | +@theme@ type="ThemeConfig" required default="{ base: '/' }" |
| 39 | + |
| 40 | +Theme Config |
| 41 | + |
| 42 | +@enabled@ type="boolean" optional default="true" |
| 43 | + |
| 44 | +Whether it's enabled |
| 45 | + |
| 46 | +::: |
| 47 | +``` |
| 48 | + |
| 49 | +By default, all attributes are allowed and displayed as-is. Common attributes include `type`, `required`, `optional`, `default` and `deprecated`. |
| 50 | + |
| 51 | +- `type` is displayed as a code block in the field header. |
| 52 | +- `default` is displayed as a labeled code block below the field header. |
| 53 | +- `required`, `optional` and `deprecated` are displayed as badges, and a deprecated field's name is colored red and struck through. |
| 54 | +- Other attributes are displayed as `Name: value` badges. |
| 55 | + |
| 56 | +### Nesting |
| 57 | + |
| 58 | +Fields can be nested to describe fields of an object type. To create a field item inside another field, increase the starting `@` by one for each level of nesting. |
| 59 | + |
| 60 | +```md |
| 61 | +::: fields |
| 62 | +@options@ type="object" |
| 63 | + |
| 64 | +Options. |
| 65 | + |
| 66 | +@@options.name@ type="string" |
| 67 | + |
| 68 | +Option name. |
| 69 | + |
| 70 | +@other@ type="string" |
| 71 | + |
| 72 | +Other field. |
| 73 | + |
| 74 | +::: |
| 75 | +``` |
| 76 | + |
| 77 | +For more syntax details, see [@mdit/plugin-field](https://mdit-plugins.github.io/field.html). |
| 78 | + |
| 79 | +## Demo |
| 80 | + |
| 81 | +::: fields |
| 82 | +@theme@ type="ThemeConfig" required default="{ base: '/' }" |
| 83 | + |
| 84 | +Theme Config |
| 85 | + |
| 86 | +@enabled@ type="boolean" optional default="true" |
| 87 | + |
| 88 | +Whether it's enabled |
| 89 | + |
| 90 | +@other@ type="string" deprecated |
| 91 | + |
| 92 | +Deprecated field |
| 93 | + |
| 94 | +::: |
| 95 | + |
| 96 | +## Options |
| 97 | + |
| 98 | +### fields |
| 99 | + |
| 100 | +- Type: `boolean` |
| 101 | +- Details: Whether to enable fields. |
| 102 | + |
| 103 | +### locales |
| 104 | + |
| 105 | +- Type: `MarkdownFieldPluginLocaleConfig` |
| 106 | + |
| 107 | +```ts |
| 108 | +interface MarkdownFieldPluginLocaleData { |
| 109 | + /** |
| 110 | + * Label text for the `default` attribute |
| 111 | + */ |
| 112 | + default: string |
| 113 | + |
| 114 | + /** |
| 115 | + * Badge text for the `required` attribute |
| 116 | + */ |
| 117 | + required: string |
| 118 | + |
| 119 | + /** |
| 120 | + * Badge text for the `optional` attribute |
| 121 | + */ |
| 122 | + optional: string |
| 123 | + |
| 124 | + /** |
| 125 | + * Badge text for the `deprecated` attribute |
| 126 | + */ |
| 127 | + deprecated: string |
| 128 | +} |
| 129 | +``` |
| 130 | + |
| 131 | +- Details: Locale config for badge texts. |
0 commit comments