(toc, maxLevel)
| 6 | * @return {Array} Headlines |
| 7 | */ |
| 8 | export function genTree(toc, maxLevel) { |
| 9 | const headlines = []; |
| 10 | const last = {}; |
| 11 | |
| 12 | toc.forEach(headline => { |
| 13 | const level = headline.level || 1; |
| 14 | const len = level - 1; |
| 15 | |
| 16 | if (level > maxLevel) { |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | if (last[len]) { |
| 21 | last[len].children = (last[len].children || []).concat(headline); |
| 22 | } else { |
| 23 | headlines.push(headline); |
| 24 | } |
| 25 | |
| 26 | last[level] = headline; |
| 27 | }); |
| 28 | |
| 29 | return headlines; |
| 30 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…