diff --git a/components/ProjectModal.tsx b/components/ProjectModal.tsx index a294bfe..a0bf027 100644 --- a/components/ProjectModal.tsx +++ b/components/ProjectModal.tsx @@ -1,11 +1,20 @@ import type { NextPage } from "next"; -import { useRef, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import styles from "../styles/ProjectModal.module.css"; import type { Project, Diary } from "../lib/content/types"; import { useCommands } from "./contexts/CommandInterface"; import { generateContent, projectEmpty } from "../lib/content/generate"; import { useModalFunctions } from "./contexts/ModalFunctions"; +// Code Highlighting +import hljs from "highlight.js"; +import rust from "highlight.js/lib/languages/rust"; +import bash from "highlight.js/lib/languages/shell"; +hljs.registerLanguage("rust", rust); +hljs.registerLanguage("bash", bash); +hljs.registerLanguage("console", bash); +hljs.registerLanguage("shell", bash); + const ProjectModal: NextPage = () => { const [visible, setVisible] = useState(false); const [currentContent, setCurrentContent] = useState(undefined); @@ -23,6 +32,10 @@ const ProjectModal: NextPage = () => { updateCmdCallbacks({ setModalVisible: setVisible, setModalContent, setModalHTML: setHTMLContent }); updateModalCallbacks({ setVisible, setContent: setModalContent, setHtml: setHTMLContent }); + useEffect(() => { + hljs.highlightAll(); + }, [HTMLContent]); + const containerRef = useRef(null); if (!visible) return <>; diff --git a/package-lock.json b/package-lock.json index 2fddd3b..b78795f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "dependencies": { "asciidoctor": "^2.2.5", "color": "^4.2.3", + "highlight.js": "^11.5.1", "next": "12.1.0", "node-fetch": "^3.2.0", "phosphor-react": "^1.3.1", @@ -2001,6 +2002,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/highlight.js": { + "version": "11.5.1", + "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-11.5.1.tgz", + "integrity": "sha512-LKzHqnxr4CrD2YsNoIf/o5nJ09j4yi/GcH5BnYz9UnVpZdS4ucMgvP61TDty5xJcFGRjnH4DpujkS9bHT3hq0Q==", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/ignore": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", @@ -5022,6 +5031,11 @@ "has-symbols": "^1.0.2" } }, + "highlight.js": { + "version": "11.5.1", + "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-11.5.1.tgz", + "integrity": "sha512-LKzHqnxr4CrD2YsNoIf/o5nJ09j4yi/GcH5BnYz9UnVpZdS4ucMgvP61TDty5xJcFGRjnH4DpujkS9bHT3hq0Q==" + }, "ignore": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", diff --git a/package.json b/package.json index f243cb0..cddc185 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "dependencies": { "asciidoctor": "^2.2.5", "color": "^4.2.3", + "highlight.js": "^11.5.1", "next": "12.1.0", "node-fetch": "^3.2.0", "phosphor-react": "^1.3.1", diff --git a/styles/customAsciidoc.scss b/styles/customAsciidoc.scss index 8f57911..3f2a183 100644 --- a/styles/customAsciidoc.scss +++ b/styles/customAsciidoc.scss @@ -2,6 +2,7 @@ font-family: sans-serif; @import "./asciidocBootSlate"; + @import "~highlight.js/styles/github"; h1 { color: var(--repl-color-link, #2ac02a);