Total Complexity | 5 |
Complexity/F | 5 |
Lines of Code | 31 |
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 | |||
15 | if (isObject(value)) { |
||
16 | obj[property] = recursiveMarkdownRender(value); |
||
17 | } else if (isString(value) && value.startsWith(markdownPreface)) { |
||
18 | // value must be a string and not start with a period (look like a path) |
||
19 | const html = remark() |
||
20 | .use(remarkHTML) |
||
21 | .processSync(value.split(markdownPreface).join('')) |
||
22 | .toString(); |
||
23 | |||
24 | obj[property] = html; |
||
25 | } |
||
26 | } |
||
27 | } |
||
28 | |||
29 | return obj; |
||
30 | }; |
||
31 | |||
32 | export { recursiveMarkdownRender }; |
||
33 |