| Total Complexity | 5 |
| Complexity/F | 5 |
| Lines of Code | 30 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | /* eslint-disable no-param-reassign */ |
||
| 2 | import remark from 'remark'; |
||
| 3 | import remarkHTML from 'remark-html'; |
||
| 4 | import isString from 'lodash/isString'; |
||
| 5 | import isObject from 'lodash/isObject'; |
||
| 6 | |||
| 7 | const markdownPreface = 'md//'; |
||
| 8 | |||
| 9 | const recursiveMarkdownRender = (obj) => { |
||
| 10 | // eslint-disable-next-line no-restricted-syntax |
||
| 11 | for (const property in obj) { |
||
| 12 | if (Object.prototype.hasOwnProperty.call(obj, property)) { |
||
| 13 | const value = obj[property]; |
||
| 14 | if (isObject(value)) { |
||
| 15 | obj[property] = recursiveMarkdownRender(value); |
||
| 16 | } else if (isString(value) && value.startsWith(markdownPreface)) { |
||
| 17 | // value must be a string and not start with a period (look like a path) |
||
| 18 | const html = remark() |
||
| 19 | .use(remarkHTML) |
||
| 20 | .processSync(value.split(markdownPreface).join('')) |
||
| 21 | .toString(); |
||
| 22 | |||
| 23 | obj[property] = html; |
||
| 24 | } |
||
| 25 | } |
||
| 26 | } |
||
| 27 | |||
| 28 | return obj; |
||
| 29 | }; |
||
| 30 | |||
| 31 | export { recursiveMarkdownRender }; |
||
| 32 |