|  | 
| 80 | 80 |  */ | 
| 81 | 81 | 
 | 
| 82 | 82 | import assert from 'assert' | 
| 83 |  | -import {directiveFromMarkdown} from 'mdast-util-directive' | 
| 84 | 83 | import {toString} from 'mdast-util-to-string' | 
| 85 | 84 | import {parse} from 'micromark/lib/parse.js' | 
| 86 | 85 | import {preprocess} from 'micromark/lib/preprocess.js' | 
| @@ -1152,27 +1151,20 @@ function extension(combined, extension) { | 
| 1152 | 1151 |  */ | 
| 1153 | 1152 | export function md(strings, ...values) { | 
| 1154 | 1153 |   // Interleave strings with `:expression`. | 
| 1155 |  | -  const tree = fromMarkdown(strings.join(':expression'), { | 
|  | 1154 | +  return fromMarkdown(strings.join(':expression'), { | 
| 1156 | 1155 |     extensions: [directive()], | 
| 1157 |  | -    mdastExtensions: [directiveFromMarkdown] | 
|  | 1156 | +    mdastExtensions: [{enter: {directiveText: enter}}] | 
| 1158 | 1157 |   }) | 
| 1159 |  | -  // Swap `:expression` nodes for values. | 
| 1160 |  | -  visit(tree) | 
| 1161 |  | -  return tree | 
| 1162 | 1158 | 
 | 
| 1163 | 1159 |   /** | 
| 1164 |  | -   * @param {Node} node | 
|  | 1160 | +   * @this {CompileContext} | 
| 1165 | 1161 |    * @returns {void} | 
| 1166 | 1162 |    */ | 
| 1167 |  | -  function visit(node) { | 
| 1168 |  | -    if ('children' in node) { | 
| 1169 |  | -      for (const [i, child] of node.children.entries()) { | 
| 1170 |  | -        if (child.type === 'textDirective' && child.name === 'expression') { | 
| 1171 |  | -          node.children[i] = /** @type {Content} */ (values.shift()) | 
| 1172 |  | -        } else { | 
| 1173 |  | -          visit(child) | 
| 1174 |  | -        } | 
| 1175 |  | -      } | 
| 1176 |  | -    } | 
|  | 1163 | +  function enter() { | 
|  | 1164 | +    const parent = this.stack[this.stack.length - 1] | 
|  | 1165 | +    assert(parent, 'expected `parent`') | 
|  | 1166 | +    assert('children' in parent, 'expected `parent`') | 
|  | 1167 | +    // @ts-expect-error: Assume `Node` can exist as a child of `parent`. | 
|  | 1168 | +    parent.children.push(values.shift()) | 
| 1177 | 1169 |   } | 
| 1178 | 1170 | } | 
0 commit comments