mirror of
https://github.com/geoffsee/open-gsio.git
synced 2025-09-08 22:56:46 +00:00
adds eslint
This commit is contained in:

committed by
Geoff Seemueller

parent
9698fc6f3b
commit
02c3253343
@@ -1,5 +1,6 @@
|
||||
import React, { useState, useEffect, useCallback } from "react";
|
||||
import { buildCodeHighlighter } from "./CodeHighlighter";
|
||||
import React, { useState, useEffect, useCallback } from 'react';
|
||||
|
||||
import { buildCodeHighlighter } from './CodeHighlighter';
|
||||
|
||||
interface CodeBlockProps {
|
||||
language: string;
|
||||
@@ -9,23 +10,19 @@ interface CodeBlockProps {
|
||||
|
||||
const highlighter = buildCodeHighlighter();
|
||||
|
||||
const CodeBlock: React.FC<CodeBlockProps> = ({
|
||||
language,
|
||||
code,
|
||||
onRenderComplete,
|
||||
}) => {
|
||||
const [html, setHtml] = useState<string>("");
|
||||
const CodeBlock: React.FC<CodeBlockProps> = ({ language, code, onRenderComplete }) => {
|
||||
const [html, setHtml] = useState<string>('');
|
||||
const [loading, setLoading] = useState<boolean>(true);
|
||||
|
||||
const highlightCode = useCallback(async () => {
|
||||
try {
|
||||
const highlighted = (await highlighter).codeToHtml(code, {
|
||||
lang: language,
|
||||
theme: "github-dark",
|
||||
theme: 'github-dark',
|
||||
});
|
||||
setHtml(highlighted);
|
||||
} catch (error) {
|
||||
console.error("Error highlighting code:", error);
|
||||
console.error('Error highlighting code:', error);
|
||||
setHtml(`<pre>${code}</pre>`);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -41,9 +38,9 @@ const CodeBlock: React.FC<CodeBlockProps> = ({
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
backgroundColor: "#24292e",
|
||||
padding: "10px",
|
||||
borderRadius: "1.5em",
|
||||
backgroundColor: '#24292e',
|
||||
padding: '10px',
|
||||
borderRadius: '1.5em',
|
||||
}}
|
||||
>
|
||||
Loading code...
|
||||
@@ -55,12 +52,12 @@ const CodeBlock: React.FC<CodeBlockProps> = ({
|
||||
<div
|
||||
dangerouslySetInnerHTML={{ __html: html }}
|
||||
style={{
|
||||
transition: "none",
|
||||
transition: 'none',
|
||||
padding: 20,
|
||||
backgroundColor: "#24292e",
|
||||
overflowX: "auto",
|
||||
borderRadius: ".37em",
|
||||
fontSize: ".75rem",
|
||||
backgroundColor: '#24292e',
|
||||
overflowX: 'auto',
|
||||
borderRadius: '.37em',
|
||||
fontSize: '.75rem',
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import { createHighlighterCore } from "shiki";
|
||||
import { createHighlighterCore } from 'shiki';
|
||||
|
||||
/* eslint-disable import/no-unresolved */
|
||||
export async function buildCodeHighlighter() {
|
||||
const [
|
||||
githubDark,
|
||||
@@ -23,26 +24,26 @@ export async function buildCodeHighlighter() {
|
||||
zig,
|
||||
wasm,
|
||||
] = await Promise.all([
|
||||
import("shiki/themes/github-dark.mjs"),
|
||||
import("shiki/langs/html.mjs"),
|
||||
import("shiki/langs/javascript.mjs"),
|
||||
import("shiki/langs/jsx.mjs"),
|
||||
import("shiki/langs/typescript.mjs"),
|
||||
import("shiki/langs/tsx.mjs"),
|
||||
import("shiki/langs/go.mjs"),
|
||||
import("shiki/langs/rust.mjs"),
|
||||
import("shiki/langs/python.mjs"),
|
||||
import("shiki/langs/java.mjs"),
|
||||
import("shiki/langs/kotlin.mjs"),
|
||||
import("shiki/langs/shell.mjs"),
|
||||
import("shiki/langs/sql.mjs"),
|
||||
import("shiki/langs/yaml.mjs"),
|
||||
import("shiki/langs/toml.mjs"),
|
||||
import("shiki/langs/markdown.mjs"),
|
||||
import("shiki/langs/json.mjs"),
|
||||
import("shiki/langs/xml.mjs"),
|
||||
import("shiki/langs/zig.mjs"),
|
||||
import("shiki/wasm"),
|
||||
import('shiki/themes/github-dark.mjs'),
|
||||
import('shiki/langs/html.mjs'),
|
||||
import('shiki/langs/javascript.mjs'),
|
||||
import('shiki/langs/jsx.mjs'),
|
||||
import('shiki/langs/typescript.mjs'),
|
||||
import('shiki/langs/tsx.mjs'),
|
||||
import('shiki/langs/go.mjs'),
|
||||
import('shiki/langs/rust.mjs'),
|
||||
import('shiki/langs/python.mjs'),
|
||||
import('shiki/langs/java.mjs'),
|
||||
import('shiki/langs/kotlin.mjs'),
|
||||
import('shiki/langs/shell.mjs'),
|
||||
import('shiki/langs/sql.mjs'),
|
||||
import('shiki/langs/yaml.mjs'),
|
||||
import('shiki/langs/toml.mjs'),
|
||||
import('shiki/langs/markdown.mjs'),
|
||||
import('shiki/langs/json.mjs'),
|
||||
import('shiki/langs/xml.mjs'),
|
||||
import('shiki/langs/zig.mjs'),
|
||||
import('shiki/wasm'),
|
||||
]);
|
||||
|
||||
// Create the highlighter instance with the loaded themes and languages
|
||||
|
Reference in New Issue
Block a user