File tree Expand file tree Collapse file tree 7 files changed +40
-54
lines changed Expand file tree Collapse file tree 7 files changed +40
-54
lines changed Original file line number Diff line number Diff line change 14
14
* limitations under the License.
15
15
*/
16
16
import { getTagId } from './htmltagenum.js' ;
17
-
18
- /**
19
- * @file Provides interfaces and helper functions for handling a JSON representation of HTML.
20
- */
21
-
22
- export interface TreeProto {
23
- tree : [ DocumentNodeProto ] ;
24
- quirks_mode : undefined | boolean ;
25
- root : number ;
26
- }
27
-
28
- export interface TextNodeProto {
29
- value : string ;
30
- num_terms : number ;
31
- }
32
- export interface ElementNodeProto {
33
- tagid : number ;
34
- value : string ;
35
- attributes : Array < AttributeProto > ;
36
- children : Array < NodeProto > ;
37
- }
38
-
39
- export interface DocumentNodeProto {
40
- tagid : 92 ; // See htmltagenum.ts
41
- children : Array < NodeProto > ;
42
- }
43
-
44
- export type NodeProto = TextNodeProto | ElementNodeProto ;
45
- export interface AttributeProto {
46
- name : string ;
47
- value ?: string ;
48
- }
17
+ import { NodeProto , ElementNodeProto , TreeProto } from './protos.js' ;
49
18
50
19
export function isElementNode ( node : NodeProto ) : node is ElementNodeProto {
51
20
return ( node as any ) . tagid !== undefined ;
Original file line number Diff line number Diff line change 13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
- import { isElementNode , NodeProto , TreeProto } from './ast.js' ;
16
+ import { isElementNode } from './ast.js' ;
17
+ import { TreeProto , NodeProto } from './protos.js' ;
17
18
18
19
// TypeScript doesn't understand importing a file with a .mjs extension, but it is perfectly valid once transpiled
19
20
// See: https://github.com/microsoft/TypeScript/issues/27957
Original file line number Diff line number Diff line change 15
15
*/
16
16
import * as ast from './ast.js' ;
17
17
import * as dom from './dom.js' ;
18
+ import { TreeProto } from './protos.js' ;
18
19
19
- // Reexport all types from ast
20
- export type {
21
- TreeProto ,
22
- DocumentNodeProto ,
23
- NodeProto ,
24
- ElementNodeProto ,
25
- TextNodeProto ,
26
- AttributeProto ,
27
- } from './ast.js' ;
28
-
20
+ export * as protos from './protos.js' ;
29
21
export interface InstructionMap {
30
22
[ key : string ] : ( element : Element ) => void ;
31
23
}
@@ -35,10 +27,10 @@ function defaultHandleError(tagName, e: Error) {
35
27
}
36
28
37
29
export function renderAst (
38
- tree : ast . TreeProto ,
30
+ tree : TreeProto ,
39
31
instructions : InstructionMap ,
40
32
{ handleError = defaultHandleError } = { }
41
- ) : ast . TreeProto {
33
+ ) : TreeProto {
42
34
const doc = dom . fromTreeProto ( tree ) ;
43
35
44
36
// TODO: Optimization opportunity by writing a custom walk instead of N querySelectorAll.
Original file line number Diff line number Diff line change
1
+ export interface TreeProto {
2
+ tree : [ DocumentNodeProto ] ;
3
+ quirks_mode : undefined | boolean ;
4
+ root : number ;
5
+ }
6
+
7
+ export interface DocumentNodeProto {
8
+ tagid : 92 ; // See htmltagenum.ts
9
+ children : Array < NodeProto > ;
10
+ }
11
+
12
+ export type NodeProto = TextNodeProto | ElementNodeProto ;
13
+
14
+ export interface TextNodeProto {
15
+ value : string ;
16
+ num_terms : number ;
17
+ }
18
+
19
+ export interface ElementNodeProto {
20
+ tagid : number ;
21
+ value : string ;
22
+ attributes : Array < AttributeProto > ;
23
+ children : Array < NodeProto > ;
24
+ }
25
+
26
+ export interface AttributeProto {
27
+ name : string ;
28
+ value ?: string ;
29
+ }
Original file line number Diff line number Diff line change 14
14
* limitations under the License.
15
15
*/
16
16
import * as parse5 from 'parse5' ;
17
- import {
18
- DocumentNodeProto ,
19
- getNumTerms ,
20
- isElementNode ,
21
- NodeProto ,
22
- TreeProto ,
23
- } from '../src/ast.js' ;
17
+ import { getNumTerms , isElementNode } from '../src/ast.js' ;
18
+ import { DocumentNodeProto , NodeProto , TreeProto } from '../src/protos.js' ;
24
19
import { getTagId } from '../src/htmltagenum.js' ;
25
20
import { renderAst , InstructionMap } from '../src/index.js' ;
26
21
Original file line number Diff line number Diff line change 13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
- import { DocumentNodeProto , NodeProto , TreeProto } from '../src/ast .js' ;
16
+ import { DocumentNodeProto , NodeProto , TreeProto } from '../src/protos .js' ;
17
17
18
18
import test from 'ava' ;
19
19
import { fromTreeProto } from '../src/dom.js' ;
Original file line number Diff line number Diff line change 14
14
* limitations under the License.
15
15
*/
16
16
import test from 'ava' ;
17
- import { DocumentNodeProto , NodeProto , TreeProto } from '../src/ast .js' ;
17
+ import { DocumentNodeProto , NodeProto , TreeProto } from '../src/protos .js' ;
18
18
import { getTagId } from '../src/htmltagenum.js' ;
19
19
import { renderAst } from '../src/index.js' ;
20
20
You can’t perform that action at this time.
0 commit comments