88 * @typedef {HastParent['children'][number] } HastChild
99 * @typedef {HastChild|HastRoot } HastNode
1010 *
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+ *
1119 * @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
1528 *
1629 * @typedef Context
1730 * @property {Document } doc
1831 * @property {boolean } [fragment=false]
1932 * @property {string } [namespace]
2033 * @property {string } [impliedNamespace]
34+ * @property {AfterTransform } [afterTransform]
2135 */
2236
2337import { webNamespaces } from 'web-namespaces'
@@ -30,6 +44,16 @@ import {find, html, svg} from 'property-information'
3044 * @param {Context } ctx
3145 */
3246function 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 ) {
3357 switch ( node . type ) {
3458 case 'root' :
3559 return root ( node , ctx )
0 commit comments