Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@vant/markdown-vetur

Package Overview
Dependencies
Maintainers
4
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vant/markdown-vetur - npm Package Compare versions

Comparing version
2.0.2
to
2.1.0
+1
-1
lib/formatter.d.ts
import { Articals } from './parser';
import { VueTag } from './type';
export declare function formatter(articals: Articals, tagPrefix?: string): VueTag | undefined;
export declare function formatter(vueTags: VueTag[], articals: Articals, tagPrefix?: string): void;

@@ -5,14 +5,18 @@ "use strict";

const utils_1 = require("./utils");
function getComponentName(artical, tagPrefix) {
if (artical.content) {
return tagPrefix + utils_1.toKebabCase(artical.content.split(' ')[0]);
function formatComponentName(name, tagPrefix) {
return tagPrefix + utils_1.toKebabCase(name);
}
function getNameFromTableTitle(tableTitle, tagPrefix) {
tableTitle = tableTitle.trim();
if (tableTitle.includes(' ')) {
return formatComponentName(tableTitle, tagPrefix).split(' ')[0];
}
return '';
}
function formatter(articals, tagPrefix = '') {
if (!articals.length) {
return;
function findTag(vueTags, name) {
const matched = vueTags.find((item) => item.name === name);
if (matched) {
return matched;
}
const tag = {
name: getComponentName(articals[0], tagPrefix),
const newTag = {
name,
slots: [],

@@ -22,4 +26,15 @@ events: [],

};
const tables = articals.filter(artical => artical.type === 'table');
tables.forEach(item => {
vueTags.push(newTag);
return newTag;
}
function formatter(vueTags, articals, tagPrefix = '') {
if (!articals.length) {
return;
}
const mainTitle = articals[0].content;
const defaultName = mainTitle
? formatComponentName(mainTitle.split(' ')[0], tagPrefix)
: '';
const tables = articals.filter((artical) => artical.type === 'table');
tables.forEach((item) => {
const { table } = item;

@@ -33,3 +48,5 @@ const prevIndex = articals.indexOf(item) - 1;

if (tableTitle.includes('Props')) {
table.body.forEach(line => {
const name = getNameFromTableTitle(tableTitle, tagPrefix) || defaultName;
const tag = findTag(vueTags, name);
table.body.forEach((line) => {
const [name, desc, type, defaultVal] = line;

@@ -49,3 +66,5 @@ tag.attributes.push({

if (tableTitle.includes('Events')) {
table.body.forEach(line => {
const name = getNameFromTableTitle(tableTitle, tagPrefix) || defaultName;
const tag = findTag(vueTags, name);
table.body.forEach((line) => {
const [name, desc] = line;

@@ -60,3 +79,5 @@ tag.events.push({

if (tableTitle.includes('Slots')) {
table.body.forEach(line => {
const name = getNameFromTableTitle(tableTitle, tagPrefix) || defaultName;
const tag = findTag(vueTags, name);
table.body.forEach((line) => {
const [name, desc] = line;

@@ -70,4 +91,3 @@ tag.slots.push({

});
return tag;
}
exports.formatter = formatter;

@@ -18,4 +18,4 @@ "use strict";

return mds
.filter(md => options.test.test(md))
.map(path => fs_extra_1.readFileSync(path, 'utf-8'));
.filter((md) => options.test.test(md))
.map((path) => fs_extra_1.readFileSync(path, 'utf-8'));
}

@@ -27,8 +27,10 @@ async function parseAndWrite(options) {

const mds = await readMarkdown(options);
const datas = mds
.map(md => formatter_1.formatter(parser_1.mdParser(md), options.tagPrefix))
.filter(item => !!item);
const webTypes = web_types_1.genWebTypes(datas, options);
const veturTags = vetur_1.genVeturTags(datas);
const veturAttributes = vetur_1.genVeturAttributes(datas);
const vueTags = [];
mds.forEach((md) => {
const parsedMd = parser_1.mdParser(md);
formatter_1.formatter(vueTags, parsedMd, options.tagPrefix);
});
const webTypes = web_types_1.genWebTypes(vueTags, options);
const veturTags = vetur_1.genVeturTags(vueTags);
const veturAttributes = vetur_1.genVeturAttributes(vueTags);
fs_extra_1.outputFileSync(path_1.join(options.outputDir, 'tags.json'), JSON.stringify(veturTags, null, 2));

@@ -35,0 +37,0 @@ fs_extra_1.outputFileSync(path_1.join(options.outputDir, 'attributes.json'), JSON.stringify(veturAttributes, null, 2));

@@ -15,3 +15,3 @@ "use strict";

line = line.replace('\\|', 'JOIN');
const items = line.split('|').map(item => item.trim().replace('JOIN', '|'));
const items = line.split('|').map((item) => item.trim().replace('JOIN', '|'));
// remove pipe character on both sides

@@ -18,0 +18,0 @@ items.pop();

{
"name": "@vant/markdown-vetur",
"version": "2.0.2",
"version": "2.1.0",
"description": "simple parse markdown to vue component description for vetur auto-completion",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const FLAG_REG = /(.*?)\s*(Props|Event)/i;
function camelCaseToKebabCase(input) {
return input.replace(/[A-Z]/g, (val, index) => (index === 0 ? '' : '-') + val.toLowerCase());
}
function removeVersionTag(str) {
return str.replace(/`(\w|\.)+`/g, '').trim();
}
function getDescription(td, isProp) {
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;
}
function codegen(artical) {
const tags = {};
let tagDescription = '';
for (let i = 0, len = artical.length; i < len; i++) {
const item = artical[i];
if (item.type === 'title' && item.level === 2) {
if (item.content) {
tagDescription = item.content;
}
}
else if (item.type === 'table') {
const before = artical[i - 1];
if (!before || !before.content) {
continue;
}
const { table } = item;
const match = FLAG_REG.exec(before.content);
if (!match || !table) {
continue;
}
const key = camelCaseToKebabCase(match[1] || 'default');
const tag = tags[key] || {
description: tagDescription,
attributes: {}
};
tags[key] = tag;
const isProp = /Props/i.test(match[2]);
table.body.forEach(td => {
const name = removeVersionTag(td[0]);
const attr = {
description: getDescription(td, isProp),
type: isProp ? td[2].replace(/`/g, '').toLowerCase() : 'event'
};
tag.attributes[name] = attr;
});
}
}
return tags;
}
exports.codegen = codegen;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable no-cond-assign */
const TITLE_REG = /^(#+)\s+([^\n]*)/;
const TABLE_REG = /^\|.+\n\|\s*-+/;
const TD_REG = /\s*`[^`]+`\s*|([^|`]+)/g;
const TABLE_SPLIT_LINE_REG = /^\|\s*-/;
function readLine(input) {
const end = input.indexOf('\n');
return input.substr(0, end !== -1 ? end : input.length);
}
function splitTableLine(line) {
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) {
let start = 0;
let isHead = true;
const end = input.length;
const table = {
head: [],
body: []
};
while (start < end) {
const target = input.substr(start);
const line = readLine(target);
if (!/^\|/.test(target)) {
break;
}
if (TABLE_SPLIT_LINE_REG.test(target)) {
isHead = false;
}
else if (!isHead && line.includes('|')) {
const matched = line.trim().match(TD_REG);
if (matched) {
table.body.push(splitTableLine(line));
}
}
start += line.length + 1;
}
return {
table,
usedLength: start
};
}
function mdParser(input) {
const artical = [];
let start = 0;
const end = input.length;
while (start < end) {
const target = input.substr(start);
let match;
if ((match = TITLE_REG.exec(target))) {
artical.push({
type: 'title',
content: match[2],
level: match[1].length
});
start += match.index + match[0].length;
}
else if ((match = TABLE_REG.exec(target))) {
const { table, usedLength } = tableParse(target.substr(match.index));
artical.push({
type: 'table',
table
});
start += match.index + usedLength;
}
else {
start += readLine(target).length + 1;
}
}
return artical;
}
exports.mdParser = mdParser;