mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(vetur): fix markdown vetur output format
This commit is contained in:
parent
17b2f2be71
commit
50252ff553
@ -13,6 +13,7 @@
|
|||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"dev": "tsc --watch",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"release": "npm run build && npm publish"
|
"release": "npm run build && npm publish"
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,13 @@ export type Tag = {
|
|||||||
description: string;
|
description: string;
|
||||||
defaults?: Array<string>;
|
defaults?: Array<string>;
|
||||||
subtags?: Array<string>;
|
subtags?: Array<string>;
|
||||||
}
|
};
|
||||||
|
|
||||||
export type Attribute = {
|
export type Attribute = {
|
||||||
description: string;
|
description: string;
|
||||||
type?: string;
|
type?: string;
|
||||||
options?: Array<string>;
|
options?: Array<string>;
|
||||||
}
|
};
|
||||||
|
|
||||||
function camelCaseToKebabCase(input: string): string {
|
function camelCaseToKebabCase(input: string): string {
|
||||||
return input.replace(
|
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) {
|
export function codegen(artical: Artical) {
|
||||||
const tags: Record<string, Tag> = {};
|
const tags: Record<string, Tag> = {};
|
||||||
let tagDescription = '';
|
let tagDescription = '';
|
||||||
@ -57,16 +73,14 @@ export function codegen(artical: Artical) {
|
|||||||
const isProp = /Props/i.test(match[2]);
|
const isProp = /Props/i.test(match[2]);
|
||||||
|
|
||||||
table.body.forEach(td => {
|
table.body.forEach(td => {
|
||||||
const attrName = td[0];
|
const name = removeVersionTag(td[0]);
|
||||||
|
|
||||||
const attr: Attribute = {
|
const attr: Attribute = {
|
||||||
description: `${td[1]}, ${
|
description: getDescription(td, isProp),
|
||||||
isProp ? 'default: ' + td[3].replace(/`/g, '') : 'params: ' + td[2]
|
|
||||||
}`,
|
|
||||||
type: isProp ? td[2].replace(/`/g, '').toLowerCase() : 'event'
|
type: isProp ? td[2].replace(/`/g, '').toLowerCase() : 'event'
|
||||||
};
|
};
|
||||||
|
|
||||||
tag.attributes[attrName] = attr;
|
tag.attributes[name] = attr;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,18 @@ function readLine(input: string) {
|
|||||||
return input.substr(0, end !== -1 ? end : input.length);
|
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) {
|
function tableParse(input: string) {
|
||||||
let start = 0;
|
let start = 0;
|
||||||
let isHead = true;
|
let isHead = true;
|
||||||
@ -44,25 +56,11 @@ function tableParse(input: string) {
|
|||||||
|
|
||||||
if (TABLE_SPLIT_LINE_REG.test(target)) {
|
if (TABLE_SPLIT_LINE_REG.test(target)) {
|
||||||
isHead = false;
|
isHead = false;
|
||||||
} else if (isHead) {
|
} else if (!isHead && line.includes('|')) {
|
||||||
// temp do nothing
|
|
||||||
} else {
|
|
||||||
const matched = line.trim().match(TD_REG);
|
const matched = line.trim().match(TD_REG);
|
||||||
|
|
||||||
if (matched) {
|
if (matched) {
|
||||||
table.body.push(
|
table.body.push(splitTableLine(line));
|
||||||
matched.map(i => {
|
|
||||||
if (i.indexOf('|') !== 0) {
|
|
||||||
return i
|
|
||||||
.trim()
|
|
||||||
.toLowerCase()
|
|
||||||
.split('|')
|
|
||||||
.map(s => s.trim())
|
|
||||||
.join('|');
|
|
||||||
}
|
|
||||||
return i.trim();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ export default {
|
|||||||
| v-model | 开关状态 | *any* | `false` |
|
| v-model | 开关状态 | *any* | `false` |
|
||||||
| title | 左侧标题 | *string* | `''` |
|
| title | 左侧标题 | *string* | `''` |
|
||||||
| border | 是否展示单元格内边框 | *boolean* | `true` |
|
| border | 是否展示单元格内边框 | *boolean* | `true` |
|
||||||
| cell-size | 单元格大小,可选值为 `large` | *string* |
|
| cell-size | 单元格大小,可选值为 `large` | *string* | - |
|
||||||
| loading | 是否为加载状态 | *boolean* | `false` |
|
| loading | 是否为加载状态 | *boolean* | `false` |
|
||||||
| disabled | 是否为禁用状态 | *boolean* | `false` |
|
| disabled | 是否为禁用状态 | *boolean* | `false` |
|
||||||
| size | 开关尺寸 | *string \| number* | `24px` |
|
| size | 开关尺寸 | *string \| number* | `24px` |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user