8
8
* @typedef {HastParent['children'][number] } HastChild
9
9
* @typedef {HastChild|HastRoot } HastNode
10
10
*
11
+ * @callback AfterTransform
12
+ * Function called when a hast node is transformed into a DOM node
13
+ * @param {HastNode } hastNode
14
+ * The hast node that was handled
15
+ * @param {Node } domNode
16
+ * The corresponding DOM node
17
+ * @returns {void }
18
+ *
11
19
* @typedef Options
12
- * @property {boolean } [fragment=false] Whether a DOM fragment should be returned
13
- * @property {Document } [document] Document interface to use (default: `globalThis.document`)
14
- * @property {string } [namespace] `namespace` to use to create elements
20
+ * @property {boolean } [fragment=false]
21
+ * Whether a DOM fragment should be returned
22
+ * @property {Document } [document]
23
+ * Document interface to use (default: `globalThis.document`)
24
+ * @property {string } [namespace]
25
+ * `namespace` to use to create elements
26
+ * @property {AfterTransform } [afterTransform]
27
+ * Callback invoked after each node transformation
15
28
*
16
29
* @typedef Context
17
30
* @property {Document } doc
18
31
* @property {boolean } [fragment=false]
19
32
* @property {string } [namespace]
20
33
* @property {string } [impliedNamespace]
34
+ * @property {AfterTransform } [afterTransform]
21
35
*/
22
36
23
37
import { webNamespaces } from 'web-namespaces'
@@ -30,6 +44,16 @@ import {find, html, svg} from 'property-information'
30
44
* @param {Context } ctx
31
45
*/
32
46
function transform ( node , ctx ) {
47
+ const transformed = one ( node , ctx )
48
+ if ( ctx . afterTransform ) ctx . afterTransform ( node , transformed )
49
+ return transformed
50
+ }
51
+
52
+ /**
53
+ * @param {HastNode } node
54
+ * @param {Context } ctx
55
+ */
56
+ function one ( node , ctx ) {
33
57
switch ( node . type ) {
34
58
case 'root' :
35
59
return root ( node , ctx )
0 commit comments