Can Highlght.JS read \r\n or \r as line break in object value?

262 Views Asked by At

I am using highlight.js to display JSON data in my react application.

Some JSON data are working fine. here is the example : enter image description here

But I have some JSON that contains a function that has \r\n and it seems that this \r\n does not want to go. For example: enter image description here

here is my code

import hljs from 'highlight.js'
import 'highlight.js/styles/github.css'
import json from 'highlight.js/lib/languages/json'
/* eslint-disable */
hljs.registerLanguage('json', json)
hljs.highlightAll()
/* eslint-enable */
interface Prop {
  code: string
  setIsFormulaEditable: () => void
}
export function ShowFormula(props: Prop): JSX.Element {
  return (
    <pre onClick={() => props.setIsFormulaEditable()}>
      <code className="json">{props.code}</code> // I have this parsed and stringified when passing it as props
    </pre>
  )
}

is it possible to remove this \r\n and replace it with a line break?

0

There are 0 best solutions below