($content, $, { transforms })
| 13 | |
| 14 | // Transform matching elements |
| 15 | export function transformElements($content, $, { transforms }) { |
| 16 | if (!transforms) return $content; |
| 17 | |
| 18 | Reflect.ownKeys(transforms).forEach(key => { |
| 19 | const $matches = $(key, $content); |
| 20 | const value = transforms[key]; |
| 21 | |
| 22 | // If value is a string, convert directly |
| 23 | if (typeof value === 'string') { |
| 24 | $matches.each((index, node) => { |
| 25 | convertNodeTo($(node), $, transforms[key]); |
| 26 | }); |
| 27 | } else if (typeof value === 'function') { |
| 28 | // If value is function, apply function to node |
| 29 | $matches.each((index, node) => { |
| 30 | const result = value($(node), $); |
| 31 | // If function returns a string, convert node to that value |
| 32 | if (typeof result === 'string') { |
| 33 | convertNodeTo($(node), $, result); |
| 34 | } |
| 35 | }); |
| 36 | } |
| 37 | }); |
| 38 | |
| 39 | return $content; |
| 40 | } |
| 41 | |
| 42 | function findMatchingSelector($, selectors, extractHtml, allowMultiple) { |
| 43 | return selectors.find(selector => { |
no test coverage detected