| 60 | } |
| 61 | |
| 62 | const Markdown = (props: Props) => { |
| 63 | let html: string |
| 64 | // TODO: set md to minimal rule set if specified |
| 65 | try { |
| 66 | html = md.render(props.children) |
| 67 | } catch (error) { |
| 68 | const message = `Failed to parse markdown for ${props.children}` |
| 69 | // TODO: onError(new Error(message)) |
| 70 | logger(`Error: ${message}`) |
| 71 | html = `<div style='background-color: #FFB81A; padding: 0.5rem;'> |
| 72 | <strong style='padding-bottom: 0.5rem;'>ERROR: Failed to parse markdown</strong> |
| 73 | <p>${props.children}</p> |
| 74 | </div>` |
| 75 | } |
| 76 | // TODO sanitize markdown or HTML |
| 77 | return <span className="coderoad-markdown" dangerouslySetInnerHTML={{ __html: html }} /> |
| 78 | } |
| 79 | |
| 80 | export default Markdown |