-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
ActorRdfParseHtml.ts
92 lines (80 loc) 路 2.35 KB
/
ActorRdfParseHtml.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import type { IAction, IActorArgs, IActorOutput, IActorTest, Mediate } from '@comunica/core';
import { Actor } from '@comunica/core';
import type * as RDF from '@rdfjs/types';
/**
* A comunica actor for rdf-parse-html events.
*
* Actor types:
* * Input: IActionRdfParseHtml: Callbacks for parsing results.
* * Test: <none>
* * Output: IActorRdfParseHtmlOutput: An HTML event listeners.
*
* @see IActionRdfParseHtml
* @see IActorRdfParseHtmlOutput
*/
export abstract class ActorRdfParseHtml extends Actor<IActionRdfParseHtml, IActorTest, IActorRdfParseHtmlOutput> {
/**
* @param args - @defaultNested {<default_bus> a <cc:components/Bus.jsonld#Bus>} bus
*/
public constructor(args: IActorRdfParseHtmlArgs) {
super(args);
}
}
export interface IActionRdfParseHtml extends IAction {
/**
* The base IRI.
*/
baseIRI: string;
/**
* The headers with which the RDF document should be parsed.
*/
headers?: Headers;
/**
* This function can be called whenever a quad has been parsed.
* @param {Quad} quad A parsed quad.
*/
emit: (quad: RDF.Quad) => void;
/**
* This function can be called when an error occurs.
* @param {Error} error An error.
*/
error: (error: Error) => void;
/**
* This function must be called when parsing is complete.
*/
end: () => void;
}
export interface IActorRdfParseHtmlOutput extends IActorOutput {
/**
* A listener for HTML parse events.
*/
htmlParseListener: IHtmlParseListener;
}
/**
* An HTML parsing listener.
*/
export interface IHtmlParseListener {
/**
* Called when a tag is opened.
* @param {string} name The tag name.
* @param {{[p: string]: string}} attributes A hash of attributes.
*/
onTagOpen: (name: string, attributes: Record<string, string>) => void;
/**
* Called when a tag is closed.
*/
onTagClose: () => void;
/**
* Called when text contents are parsed.
* Note that this can be called multiple times per tag,
* when for example the string is spread over multiple chunks.
* @param {string} data A string.
*/
onText: (data: string) => void;
/**
* Called when parsing has ended.
*/
onEnd: () => void;
}
export type IActorRdfParseHtmlArgs = IActorArgs<IActionRdfParseHtml, IActorTest, IActorRdfParseHtmlOutput>;
export type MediatorRdfParseHtml = Mediate<IActionRdfParseHtml, IActorRdfParseHtmlOutput>;