html.experimental.custom.tags/attributes for Microsoft/vscode#62976

This commit is contained in:
Pine Wu
2018-11-28 16:34:12 -08:00
parent 3725e59112
commit d198091b68
7 changed files with 139 additions and 16 deletions

View File

@@ -0,0 +1,58 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ITagSet, IAttributeSet, HTMLTagSpecification } from 'vscode-html-languageservice';
interface Tag {
label: string;
description: string;
attributes: Attribute[];
}
interface Attribute {
label: string;
description: string;
}
interface RawTagSet {
tags: Tag[];
}
interface RawAttributeSet {
attributes: Attribute[];
}
export function parseTagSet(source: string): ITagSet {
const tagSet: ITagSet = {};
let rawTagSet: RawTagSet;
try {
rawTagSet = JSON.parse(source);
} catch (err) {
return {};
}
rawTagSet.tags.forEach(c => {
tagSet[c.label] = new HTMLTagSpecification(c.description, c.attributes.map(a => a.label));
});
return tagSet;
}
export function parseAttributes(source: string): IAttributeSet {
const attributeSet: IAttributeSet = {};
let rawAttributeSet: RawAttributeSet;
try {
rawAttributeSet = JSON.parse(source);
} catch (err) {
return {};
}
rawAttributeSet.attributes.forEach(ag => {
attributeSet[ag.label] = {
...ag
};
});
return attributeSet;
}