This commit is contained in:
Pine Wu
2019-01-16 09:59:06 -08:00
parent c8809009f3
commit 9a3ef8c4b2
6 changed files with 37 additions and 110 deletions

View File

@@ -3,56 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ITagSet, IAttributeSet, HTMLTagSpecification } from 'vscode-html-languageservice';
import { HTMLData } 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;
export function parseHTMLData(source: string): HTMLData {
return JSON.parse(source);
}