feat(VantMarkdownVetur): support arguments of events (#10474)

* feat(VantMarkdownVetur): support arguments of events

* fix(vant): fix mistake in readme

* docs(vant): fix ',' to ','

* fix(vant-markdown-vetur): support events arguments

* docs(AddressList): fix mistake

* docs(AddressList): prettier

* docs(Collapse): adjust

* docs(dropdown-menu): adjust

* docs(ImagePreview): adjust

* fix(vant-markdown-vetur): fix format

* fix(vant-markdown-vetur): fix formatter
This commit is contained in:
Nemo Shen
2022-04-10 10:37:02 +08:00
committed by GitHub
parent d5a9202ddf
commit 7ce66c7939
44 changed files with 133 additions and 91 deletions
+41 -2
View File
@@ -1,12 +1,50 @@
/* eslint-disable no-continue */
import { Articals } from './parser';
import { formatOptions, formatType, removeVersion, toKebabCase } from './utils';
import { VueTag } from './type';
import { VueEventArgument, VueTag } from './type';
function formatComponentName(name: string, tagPrefix: string) {
return tagPrefix + toKebabCase(name);
}
/**
* format arugments of events
* input = value: { foo: foo or 1, bar: bar or 2 }, value2: { one: 1 and 1, two: 2 and 2 }, foo: bar
* output = [{ name: 'value', type: '{ foo: foo or 1, bar: bar or 2 }' }, { name: 'value2', type: '{ one: 1 and 1, two: 2 and 2 }'}, { name: 'foo', type: 'bar' }]
*/
function formatArguments(input: string): VueEventArgument[] {
if (input === '-') return [];
const args: VueEventArgument[] = [];
const items = [];
input = formatType(input);
while (input.length > 0) {
if (/(?!_)\w/.test(input[0])) {
const val = input.match(/(\w|\s|\p{P}|\||\[|\]|>|<)+/)![0] || '';
input = input.substring(val.length);
items.push(val);
} else if (input[0] === '{') {
const val = input.match(/\{[^}]+\}/)![0] || '';
input = input.substring(val.length);
items.push(val);
} else if ([':', ',', '_', ' '].includes(input[0])) {
input = input.substring(1);
} else {
const val = input.match(/( |'|\||\w)+/)![0] || '';
input = input.substring(val.length);
items.push(val);
}
}
for (let i = 0; i < items.length; i += 2) {
args.push({
name: items[i],
type: items[i + 1],
});
}
return args;
}
function getNameFromTableTitle(tableTitle: string, tagPrefix: string) {
tableTitle = tableTitle.trim();
if (tableTitle.includes(' ')) {
@@ -84,10 +122,11 @@ export function formatter(
const tag = findTag(vueTags, name);
table.body.forEach((line) => {
const [name, desc] = line;
const [name, desc, args] = line;
tag.events!.push({
name: removeVersion(name),
description: desc,
arguments: formatArguments(args),
});
});
return;
+4 -2
View File
@@ -25,9 +25,11 @@ function readLine(input: string) {
}
function splitTableLine(line: string) {
line = line.replace('\\|', 'JOIN');
line = line.replace(/\\\|/g, 'JOIN');
const items = line.split('|').map((item) => item.trim().replace('JOIN', '|'));
const items = line
.split('|')
.map((item) => item.trim().replace(/JOIN/g, '|'));
// remove pipe character on both sides
items.pop();