fix(vetur): fix markdown vetur output format

This commit is contained in:
陈嘉涵
2020-01-15 16:05:20 +08:00
parent 17b2f2be71
commit 50252ff553
4 changed files with 37 additions and 24 deletions
+21 -7
View File
@@ -8,13 +8,13 @@ export type Tag = {
description: string;
defaults?: Array<string>;
subtags?: Array<string>;
}
};
export type Attribute = {
description: string;
type?: string;
options?: Array<string>;
}
};
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('<br>', '') : '';
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<string, Tag> = {};
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;
});
}
}