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

View File

@ -13,6 +13,7 @@
"lib"
],
"scripts": {
"dev": "tsc --watch",
"build": "tsc",
"release": "npm run build && npm publish"
}

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;
});
}
}

View File

@ -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));
}
}

View File

@ -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` |