( node: MarkdownNode, state: RenderState, parentType: MarkdownNode['type'], nextSibling?: MarkdownNode, )
| 852 | } |
| 853 | |
| 854 | const renderNode = ( |
| 855 | node: MarkdownNode, |
| 856 | state: RenderState, |
| 857 | parentType: MarkdownNode['type'], |
| 858 | nextSibling?: MarkdownNode, |
| 859 | ): ReactNode[] => { |
| 860 | switch (node.type) { |
| 861 | case 'root': |
| 862 | return renderNodes( |
| 863 | (node as Root).children as MarkdownNode[], |
| 864 | state, |
| 865 | node.type, |
| 866 | ) |
| 867 | |
| 868 | case 'paragraph': { |
| 869 | const children = renderNodes( |
| 870 | (node as Paragraph).children as MarkdownNode[], |
| 871 | state, |
| 872 | node.type, |
| 873 | ) |
| 874 | const nodes = [...children] |
| 875 | if (parentType === 'listItem') { |
| 876 | nodes.push('\n') |
| 877 | } else if (parentType === 'blockquote') { |
| 878 | nodes.push('\n') |
| 879 | } else { |
| 880 | const isTightFollowup = |
| 881 | parentType === 'root' && |
| 882 | nextSibling && |
| 883 | (nextSibling.type === 'blockquote' || nextSibling.type === 'list') |
| 884 | nodes.push(isTightFollowup ? '\n' : '\n\n') |
| 885 | } |
| 886 | return nodes |
| 887 | } |
| 888 | |
| 889 | case 'text': |
| 890 | return [(node as Text).value] |
| 891 | |
| 892 | case 'strong': { |
| 893 | const children = renderNodes( |
| 894 | (node as Strong).children as MarkdownNode[], |
| 895 | state, |
| 896 | node.type, |
| 897 | ) |
| 898 | return [ |
| 899 | <span key={state.nextKey()} attributes={TextAttributes.BOLD}> |
| 900 | {wrapSegmentsInFragments(children, state.nextKey())} |
| 901 | </span>, |
| 902 | ] |
| 903 | } |
| 904 | |
| 905 | case 'emphasis': { |
| 906 | const children = renderNodes( |
| 907 | (node as Emphasis).children as MarkdownNode[], |
| 908 | state, |
| 909 | node.type, |
| 910 | ) |
| 911 | return [ |
no test coverage detected