(node: any, count = 1)
| 1 | export default function transform(node: any, count = 1) { |
| 2 | count += 1; |
| 3 | node.cid = `${node.source || node.id}-${count}`; |
| 4 | if (node.type === 'code') { |
| 5 | if (node.value.includes('\n')) { |
| 6 | node.type = 'pre'; |
| 7 | } |
| 8 | } |
| 9 | if (node.type === 'text') { |
| 10 | const value = node.value.trim().toLowerCase(); |
| 11 | if (value.startsWith('{') && value.endsWith('}')) { |
| 12 | try { |
| 13 | JSON.parse(value); |
| 14 | node.type = 'pre'; |
| 15 | } catch (exception) {} |
| 16 | } |
| 17 | |
| 18 | if (value.startsWith('<!doctype html>') && value.endsWith('</html>')) { |
| 19 | node.type = 'pre'; |
| 20 | } |
| 21 | } |
| 22 | if (node.children) { |
| 23 | node.children = node.children.map((node: any, index: number) => |
| 24 | transform(node, count + index) |
| 25 | ); |
| 26 | } |
| 27 | return node; |
| 28 | } |
no test coverage detected