diff --git a/packages/vant-markdown-vetur/package.json b/packages/vant-markdown-vetur/package.json index 86f4af52c..e61ec4f29 100644 --- a/packages/vant-markdown-vetur/package.json +++ b/packages/vant-markdown-vetur/package.json @@ -13,6 +13,7 @@ "lib" ], "scripts": { + "dev": "tsc --watch", "build": "tsc", "release": "npm run build && npm publish" } diff --git a/packages/vant-markdown-vetur/src/codegen.ts b/packages/vant-markdown-vetur/src/codegen.ts index 111ddb9ac..2ec022e3b 100644 --- a/packages/vant-markdown-vetur/src/codegen.ts +++ b/packages/vant-markdown-vetur/src/codegen.ts @@ -8,13 +8,13 @@ export type Tag = { description: string; defaults?: Array; subtags?: Array; -} +}; export type Attribute = { description: string; type?: string; options?: Array; -} +}; function camelCaseToKebabCase(input: string): string { return input.replace( @@ -23,6 +23,22 @@ function camelCaseToKebabCase(input: string): string { ); } +function removeVersionTag(str: string) { + return str.replace(/`(\w|\.)+`/g, '').trim(); +} + +function getDescription(td: string[], isProp: boolean) { + const desc = td[1] ? td[1].replace('
', '') : ''; + const type = td[2] ? td[2].replace(/\*/g, '') : ''; + const defaultVal = td[3] ? td[3].replace(/`/g, '') : ''; + + if (isProp) { + return `${desc}, 默认值: ${defaultVal}, 类型: ${type}`; + } + + return desc; +} + export function codegen(artical: Artical) { const tags: Record = {}; let tagDescription = ''; @@ -57,16 +73,14 @@ export function codegen(artical: Artical) { const isProp = /Props/i.test(match[2]); table.body.forEach(td => { - const attrName = td[0]; + const name = removeVersionTag(td[0]); const attr: Attribute = { - description: `${td[1]}, ${ - isProp ? 'default: ' + td[3].replace(/`/g, '') : 'params: ' + td[2] - }`, + description: getDescription(td, isProp), type: isProp ? td[2].replace(/`/g, '').toLowerCase() : 'event' }; - tag.attributes[attrName] = attr; + tag.attributes[name] = attr; }); } } diff --git a/packages/vant-markdown-vetur/src/md-parser.ts b/packages/vant-markdown-vetur/src/md-parser.ts index 4f6be3ba4..dc23c79f0 100644 --- a/packages/vant-markdown-vetur/src/md-parser.ts +++ b/packages/vant-markdown-vetur/src/md-parser.ts @@ -24,6 +24,18 @@ function readLine(input: string) { return input.substr(0, end !== -1 ? end : input.length); } +function splitTableLine(line: string) { + line = line.replace('\\|', 'JOIN'); + + const items = line.split('|').map(item => item.trim().replace('JOIN', '|')); + + // remove pipe character on both sides + items.pop(); + items.shift(); + + return items; +} + function tableParse(input: string) { let start = 0; let isHead = true; @@ -44,25 +56,11 @@ function tableParse(input: string) { if (TABLE_SPLIT_LINE_REG.test(target)) { isHead = false; - } else if (isHead) { - // temp do nothing - } else { + } else if (!isHead && line.includes('|')) { const matched = line.trim().match(TD_REG); if (matched) { - table.body.push( - matched.map(i => { - if (i.indexOf('|') !== 0) { - return i - .trim() - .toLowerCase() - .split('|') - .map(s => s.trim()) - .join('|'); - } - return i.trim(); - }) - ); + table.body.push(splitTableLine(line)); } } diff --git a/src/switch-cell/README.zh-CN.md b/src/switch-cell/README.zh-CN.md index 8ef1d28fa..859dc9bd8 100644 --- a/src/switch-cell/README.zh-CN.md +++ b/src/switch-cell/README.zh-CN.md @@ -62,7 +62,7 @@ export default { | v-model | 开关状态 | *any* | `false` | | title | 左侧标题 | *string* | `''` | | border | 是否展示单元格内边框 | *boolean* | `true` | -| cell-size | 单元格大小,可选值为 `large` | *string* | +| cell-size | 单元格大小,可选值为 `large` | *string* | - | | loading | 是否为加载状态 | *boolean* | `false` | | disabled | 是否为禁用状态 | *boolean* | `false` | | size | 开关尺寸 | *string \| number* | `24px` |