(tree)
| 1 | const walk = require('../walk'); |
| 2 | |
| 3 | function stringify(tree) { |
| 4 | let output = ''; |
| 5 | |
| 6 | walk(tree, (node) => { |
| 7 | if (node.used) { |
| 8 | return; |
| 9 | } |
| 10 | node.used = true; |
| 11 | if (node.type === 'root') { |
| 12 | return; |
| 13 | } |
| 14 | if (node.type === 'bold') { |
| 15 | output += '*'; |
| 16 | node.children.forEach((child) => { |
| 17 | output += stringify(child); |
| 18 | }); |
| 19 | output += '*'; |
| 20 | } |
| 21 | |
| 22 | if (node.type === 'italic') { |
| 23 | output += '_'; |
| 24 | node.children.forEach((child) => { |
| 25 | output += stringify(child); |
| 26 | }); |
| 27 | output += '_'; |
| 28 | } |
| 29 | |
| 30 | if (node.type === 'strike') { |
| 31 | output += '~'; |
| 32 | node.children.forEach((child) => { |
| 33 | output += stringify(child); |
| 34 | }); |
| 35 | output += '~'; |
| 36 | } |
| 37 | |
| 38 | if (node.type === 'code') { |
| 39 | output += node.source; |
| 40 | } |
| 41 | |
| 42 | if (node.type === 'pre') { |
| 43 | output += node.source; |
| 44 | } |
| 45 | |
| 46 | if (node.type === 'quote') { |
| 47 | output += '> '; |
| 48 | node.children.forEach((child) => { |
| 49 | output += stringify(child); |
| 50 | }); |
| 51 | } |
| 52 | |
| 53 | if (node.type === 'header') { |
| 54 | output += `${'#'.repeat(node.depth)} `; |
| 55 | node.children.forEach((child) => { |
| 56 | output += stringify(child); |
| 57 | }); |
| 58 | } |
| 59 | |
| 60 | if (node.type === 'list') { |
no test coverage detected