Skip to content

Commit 4673c1d

Browse files
Ecmel ErcanEcmel Ercan
authored andcommitted
Add htmlparser2
1 parent 7682928 commit 4673c1d

File tree

6 files changed

+192
-1
lines changed

6 files changed

+192
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"vscode-languageclient": "2.3.0",
4848
"vscode-languageserver": "2.2.1",
4949
"vscode-languageserver-types": "1.0.1",
50-
"vscode-css-languageservice": "1.0.4"
50+
"vscode-css-languageservice": "1.0.4",
51+
"htmlparser2": "3.9.0"
5152
}
5253
}

srv/server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import * as ls from 'vscode-languageserver';
66
import * as lst from 'vscode-languageserver-types';
77
import * as css from 'vscode-css-languageservice';
8+
import * as htm from 'htmlparser2';
89

910
let conn = ls.createConnection(new ls.IPCMessageReader(process), new ls.IPCMessageWriter(process));
1011
let docs = new ls.TextDocuments();

typings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"htmlparser2": "registry:npm/htmlparser2#3.9.0+20160616165259"
4+
}
5+
}

typings/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference path="modules/htmlparser2/index.d.ts" />
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
// Generated by typings
2+
// Source: https://raw.githubusercontent.com/typed-typings/npm-htmlparser2/23d1783b0983d7af0a2dd22bcedd9cf853119317/lib/index.d.ts
3+
declare module '~htmlparser2/lib/index' {
4+
import { Writable } from 'stream';
5+
import { EventEmitter } from 'events';
6+
7+
export interface TokenizerOptions {
8+
/**
9+
* If set to true, entities within the document will be decoded. Defaults to false.
10+
*/
11+
decodeEntities: boolean;
12+
/**
13+
* Disables the special behavior for script/style tags (false by default)
14+
*/
15+
xmlMode?: boolean;
16+
}
17+
18+
export interface ParserOptions extends TokenizerOptions {
19+
/**
20+
* Call .toLowerCase for each attribute name (true if xmlMode is `false`)
21+
*/
22+
lowerCaseAttributeNames?: boolean;
23+
/**
24+
* Call .toLowerCase for each tag name (true if xmlMode is `false`)
25+
*/
26+
lowerCaseTags?: boolean;
27+
/**
28+
* If set to true, self-closing tags will trigger the onclosetag event even if xmlMode is not set to true.
29+
* NOTE: If xmlMode is set to true then self-closing tags will always be recognized.
30+
*/
31+
recognizeSelfClosing?: boolean;
32+
/***
33+
* If set to true, CDATA sections will be recognized as text even if the xmlMode option is not enabled.
34+
* NOTE: If xmlMode is set to true then CDATA sections will always be recognized as text.
35+
*/
36+
recognizeCDATA?: boolean;
37+
}
38+
39+
export interface ParserAttributes {
40+
[key: string]: string;
41+
}
42+
43+
export interface Callbacks {
44+
oncdataend? (): any;
45+
oncdatastart? (): any;
46+
onclosetag? (tagName: string): any;
47+
oncomment? (comment: string): any;
48+
oncommentend? (): any;
49+
onattribute? (key: string, value: string): any;
50+
onerror? (err: Error): any;
51+
onopentag? (tagName: string, attribs: ParserAttributes): any;
52+
onopentagname? (tagName: string): any;
53+
onprocessinginstruction? (name: string, value: string): any;
54+
onreset? (): any;
55+
ontext? (text: string): any;
56+
onend? (): any;
57+
}
58+
59+
export class Tokenizer {
60+
61+
constructor (options: TokenizerOptions, cbs: Callbacks);
62+
63+
write (chunk: string | Buffer): void;
64+
pause (): void;
65+
resume (): void;
66+
end (): void;
67+
reset (): void;
68+
69+
}
70+
71+
export class Parser extends EventEmitter implements Callbacks {
72+
73+
constructor (cbs: Callbacks, options: ParserOptions);
74+
75+
ontext (text: string): void;
76+
onopentagname (name: string): void;
77+
onopentagend (): void;
78+
onclosetag (name: string): void;
79+
onselfclosingtag (): void;
80+
onattribname (name: string): void;
81+
onattribdata (value: string): void;
82+
onattribend (): void;
83+
ondeclaration (value: string): void;
84+
onprocessinginstruction (value: string): void;
85+
oncomment (value: string): void;
86+
oncdata (value: string): void;
87+
onerror (err: Error): void;
88+
onend (): void;
89+
reset (): void;
90+
parseComplete (data: string): void;
91+
write (chunk: string): void;
92+
end (chunk: string): void;
93+
pause (): void;
94+
resume (): void;
95+
96+
// Aliases for backward compat.
97+
parseChunk (chunk: string): void;
98+
done (chunk: string): void;
99+
100+
}
101+
102+
export class WritableStream extends Writable {
103+
104+
constructor (cbs: Callbacks, options: ParserOptions);
105+
106+
}
107+
108+
export class Stream extends WritableStream {
109+
110+
constructor (options: ParserOptions);
111+
112+
readable: boolean;
113+
114+
on (name: 'attribute', listener: (name: string, key: string, value: string) => any): this;
115+
on (name: 'cdatastart', listener: (name: string) => any): this;
116+
on (name: 'cdataend', listener: (name: string) => any): this;
117+
on (name: 'text', listener: (name: string, text: string) => any): this;
118+
on (name: 'processinginstruction', listener: (name: string, key: string, value: string) => any): this;
119+
on (name: 'comment', listener: (name: string, text: string) => any): this;
120+
on (name: 'commentend', listener: (name: string) => any): this;
121+
on (name: 'closetag', listener: (name: string, tagName: string) => any): this;
122+
on (name: 'opentag', listener: (name: string, tagName: string, attribs: ParserAttributes) => any): this;
123+
on (name: 'opentagname', listener: (name: string, tagName: string) => any): this;
124+
on (name: 'error', listener: (name: string, error: Error) => any): this;
125+
on (name: 'end', listener: (name: string) => any): this;
126+
on (name: string, listener: (...args: any[]) => any): this;
127+
128+
}
129+
130+
export class CollectingHandler implements Callbacks {
131+
132+
constructor (cbs: Callbacks);
133+
134+
oncdataend (): void;
135+
oncdatastart (): void;
136+
onclosetag (tagName: string): void;
137+
oncomment (comment: string): void;
138+
oncommentend (): void;
139+
onattribute (key: string, value: string): void;
140+
onerror (err: Error): void;
141+
onopentag (tagName: string, attribs: ParserAttributes): void;
142+
onopentagname (tagName: string): void;
143+
onprocessinginstruction (name: string, value: string): void;
144+
onreset (): void;
145+
ontext (text: string): void;
146+
onend (): void;
147+
restart (): void;
148+
149+
}
150+
151+
export var EVENTS: {
152+
attribute: number;
153+
cdatastart: number;
154+
cdataend: number;
155+
text: number;
156+
processinginstruction: number;
157+
comment: number;
158+
commentend: number;
159+
closetag: number;
160+
opentag: number;
161+
opentagname: number;
162+
error: number;
163+
end: number;
164+
};
165+
}
166+
declare module 'htmlparser2/lib/index' {
167+
export * from '~htmlparser2/lib/index';
168+
}
169+
declare module 'htmlparser2' {
170+
export * from '~htmlparser2/lib/index';
171+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"resolution": "main",
3+
"tree": {
4+
"src": "https://raw.githubusercontent.com/typed-typings/npm-htmlparser2/23d1783b0983d7af0a2dd22bcedd9cf853119317/typings.json",
5+
"raw": "registry:npm/htmlparser2#3.9.0+20160616165259",
6+
"main": "lib/index.d.ts",
7+
"version": "^3.9.0",
8+
"global": false,
9+
"name": "htmlparser2",
10+
"type": "typings"
11+
}
12+
}

0 commit comments

Comments
 (0)