( customDecoratorComponents?: CustomDecoratorComponents )
| 18 | import { classNames, getTextContent, getListNumber } from "./utils"; |
| 19 | |
| 20 | export const createRenderChildText = ( |
| 21 | customDecoratorComponents?: CustomDecoratorComponents |
| 22 | ) => (properties: DecorationType[]) => { |
| 23 | return properties?.map(([text, decorations], i) => { |
| 24 | if (!decorations) { |
| 25 | return <React.Fragment key={i}>{text}</React.Fragment>; |
| 26 | } |
| 27 | |
| 28 | return decorations.reduceRight((element, decorator) => { |
| 29 | const renderText = () => { |
| 30 | switch (decorator[0]) { |
| 31 | case "h": |
| 32 | return ( |
| 33 | <span key={i} className={`notion-${decorator[1]}`}> |
| 34 | {element} |
| 35 | </span> |
| 36 | ); |
| 37 | case "c": |
| 38 | return ( |
| 39 | <code key={i} className="notion-inline-code"> |
| 40 | {element} |
| 41 | </code> |
| 42 | ); |
| 43 | case "b": |
| 44 | return <b key={i}>{element}</b>; |
| 45 | case "i": |
| 46 | return <em key={i}>{element}</em>; |
| 47 | case "s": |
| 48 | return <s key={i}>{element}</s>; |
| 49 | case "a": |
| 50 | return ( |
| 51 | <a className="notion-link" href={decorator[1]} key={i}> |
| 52 | {element} |
| 53 | </a> |
| 54 | ); |
| 55 | |
| 56 | default: |
| 57 | return <React.Fragment key={i}>{element}</React.Fragment>; |
| 58 | } |
| 59 | }; |
| 60 | |
| 61 | const CustomComponent = customDecoratorComponents?.[decorator[0]]; |
| 62 | |
| 63 | if (CustomComponent) { |
| 64 | const props = (decorator[1] |
| 65 | ? { |
| 66 | decoratorValue: decorator[1] |
| 67 | } |
| 68 | : {}) as CustomDecoratorComponentProps<typeof decorator[0]>; |
| 69 | |
| 70 | return ( |
| 71 | <CustomComponent |
| 72 | key={i} |
| 73 | {...(props as any)} |
| 74 | renderComponent={renderText} |
| 75 | > |
| 76 | {text} |
| 77 | </CustomComponent> |
no test coverage detected