import dedent from 'dedent'; import { HTMLAttributes, useState } from 'react'; import { classList } from '../utilities/cssClasses'; import { CodeBlock } from './codeblock'; interface Props extends HTMLAttributes { version: string; } export const HTMLTagsExample = ({ className, version, ...props }: Props) => { const [cdn, setCDN] = useState('cdnjs'); const links = { cdnjs: { link: 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/{version}/styles/default.min.css', script: 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/{version}/highlight.min.js', lang: 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/{version}/languages/go.min.js', }, jsDeliver: { link: 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@{version}/build/styles/default.min.css', script: 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@{version}/build/highlight.min.js', lang: 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@{version}/build/languages/go.min.js', }, unpkg: { link: 'https://unpkg.com/@highlightjs/cdn-assets@{version}/styles/default.min.css', script: 'https://unpkg.com/@highlightjs/cdn-assets@{version}/highlight.min.js', lang: 'https://unpkg.com/@highlightjs/cdn-assets@{version}/languages/go.min.js', }, 'Self hosted': { link: '/path/to/styles/default.css', script: '/path/to/highlight.min.js', }, }; const codeBlockSource = [ dedent` `, ]; if (links[cdn].lang) { codeBlockSource.push(dedent` `); } codeBlockSource.push(''); const codeBlock = codeBlockSource .join('\n\n') .replace(/{version}/g, version) .trim(); return ( {Object.keys(links).map((name, index) => ( setCDN(name)} > {name} ))} ); };