Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 147x 1x 146x 146x 146x 135x | import { Fragment } from 'react'; // based in part on this SO answer: https://codereview.stackexchange.com/a/211511 export default function Plaintext({text}) { if (text==null) { return (<pre data-testid="plaintext-empty"></pre>) } const textToRender = typeof text === "string" ? text : JSON.stringify(text, null, 2); const [firstLine, ...rest] = textToRender.split('\n') return ( <pre data-testid="plaintext"> <span>{ firstLine }</span> { rest.map((line, i) => ( <Fragment key={i}> <br /> <span>{ line }</span> </Fragment> )) } </pre> ); } |