diff --git a/packages/vant-markdown-vetur/src/formatter.ts b/packages/vant-markdown-vetur/src/formatter.ts index 162ccc5f1..b0e9fef37 100644 --- a/packages/vant-markdown-vetur/src/formatter.ts +++ b/packages/vant-markdown-vetur/src/formatter.ts @@ -1,6 +1,6 @@ /* eslint-disable no-continue */ import { Articals } from './parser'; -import { formatType, removeVersion, toKebabCase } from './utils'; +import { formatOptions, formatType, removeVersion, toKebabCase } from './utils'; import { VueTag } from './type'; function formatComponentName(name: string, tagPrefix: string) { @@ -64,11 +64,12 @@ export function formatter( const tag = findTag(vueTags, name); table.body.forEach((line) => { - const [name, desc, type, defaultVal] = line; + const [name, desc, type, defaultVal, options] = line; tag.attributes!.push({ name: removeVersion(name), default: defaultVal, description: desc, + options: formatOptions(options), value: { type: formatType(type), kind: 'expression', diff --git a/packages/vant-markdown-vetur/src/type.ts b/packages/vant-markdown-vetur/src/type.ts index 248eb98ab..f8b950f5b 100644 --- a/packages/vant-markdown-vetur/src/type.ts +++ b/packages/vant-markdown-vetur/src/type.ts @@ -20,6 +20,7 @@ export type VueAttribute = { name: string; default: string; description: string; + options: string[] value: { kind: 'expression'; type: string; @@ -44,6 +45,7 @@ export type VeturTags = Record; export type VeturAttribute = { type: string; description: string; + options?: string[]; }; export type VeturAttributes = Record; diff --git a/packages/vant-markdown-vetur/src/utils.ts b/packages/vant-markdown-vetur/src/utils.ts index a25e944f4..0714b0742 100644 --- a/packages/vant-markdown-vetur/src/utils.ts +++ b/packages/vant-markdown-vetur/src/utils.ts @@ -20,3 +20,9 @@ export function formatType(type: string) { export function normalizePath(path: string): string { return path.replace(/\\/g, '/'); } + +// `default` `primary` -> ['default', 'primary'] +export function formatOptions(options?: string) { + if (!options) return [] + return options.replace(/`/g, '').split(' ') +} diff --git a/packages/vant-markdown-vetur/src/vetur.ts b/packages/vant-markdown-vetur/src/vetur.ts index cf52216a6..ff3c424fe 100644 --- a/packages/vant-markdown-vetur/src/vetur.ts +++ b/packages/vant-markdown-vetur/src/vetur.ts @@ -1,4 +1,4 @@ -import { VueTag, VeturTags, VeturAttributes } from './type'; +import { VueTag, VeturTags, VeturAttributes, VeturAttribute } from './type'; export function genVeturTags(tags: VueTag[]) { const veturTags: VeturTags = {}; @@ -18,10 +18,16 @@ export function genVeturAttributes(tags: VueTag[]) { tags.forEach(tag => { if (tag.attributes) { tag.attributes.forEach(attr => { - veturAttributes[`${tag.name}/${attr.name}`] = { + let attribute: VeturAttribute = { type: attr.value.type, - description: `${attr.description}, 默认值: ${attr.default}`, - }; + description: `${attr.description}, 默认值: ${attr.default}` + } + + if (attr.options.length > 0) { + attribute.options = attr.options + } + + veturAttributes[`${tag.name}/${attr.name}`] = attribute; }); } });