diff --git a/src/address/ABI.tsx b/src/address/ABI.tsx index 7190f4e..a714367 100644 --- a/src/address/ABI.tsx +++ b/src/address/ABI.tsx @@ -1,10 +1,5 @@ import React from "react"; -import { Light as SyntaxHighlighter } from "react-syntax-highlighter"; -import hljs from "highlight.js"; -import docco from "react-syntax-highlighter/dist/esm/styles/hljs/docco"; - -import hljsDefineSolidity from "highlightjs-solidity"; -hljsDefineSolidity(hljs); +import { SyntaxHighlighter, docco } from "../highlight-init"; type ABIProps = { abi: any[]; diff --git a/src/address/Contract.tsx b/src/address/Contract.tsx index 7ddfe56..5432f51 100644 --- a/src/address/Contract.tsx +++ b/src/address/Contract.tsx @@ -1,12 +1,7 @@ import React from "react"; -import { Light as SyntaxHighlighter } from "react-syntax-highlighter"; -import hljs from "highlight.js"; -import docco from "react-syntax-highlighter/dist/esm/styles/hljs/docco"; +import { SyntaxHighlighter, docco } from "../highlight-init"; import { useContract } from "../useSourcify"; - -import hljsDefineSolidity from "highlightjs-solidity"; import { useAppConfigContext } from "../useAppConfig"; -hljsDefineSolidity(hljs); type ContractProps = { checksummedAddress: string; diff --git a/src/highlight-init.ts b/src/highlight-init.ts new file mode 100644 index 0000000..f8318eb --- /dev/null +++ b/src/highlight-init.ts @@ -0,0 +1,14 @@ +import { Light as SyntaxHighlighter } from "react-syntax-highlighter"; + +// @ts-ignore +import hljs from "highlight.js/lib/core"; + +// @ts-ignore +import json from "highlight.js/lib/languages/json"; +import docco from "react-syntax-highlighter/dist/esm/styles/hljs/docco"; + +import hljsDefineSolidity from "highlightjs-solidity"; +hljsDefineSolidity(hljs); +hljs.registerLanguage("json", json); + +export { SyntaxHighlighter, docco };