import React, { useState } from "react" import hljs from "highlight.js" import * as hooks from "./hooks" import LinkButton from "./util/linkButton" MAX_HIGHLIGHT_LENGTH = 10 * 1024 # 10 KiB export default CodeViewer = (props) -> [code, setCode] = useState "Loading..." [highlight, setHighlight] = useState true # Fetch the content on first mount (and after first render) hooks.useFetchContent props.id, (meta, resp) -> resp = await resp.text() if meta.length < MAX_HIGHLIGHT_LENGTH setCode hljs.highlightAuto(resp).value else setHighlight false setCode resp
{ if highlight
        else
          
{code}
}
New Paste