From b4a87a6de3bd84afa814c2f53cb065a3f007be06 Mon Sep 17 00:00:00 2001 From: aadarshkt Date: Sun, 23 Mar 2025 18:19:52 +0530 Subject: [PATCH] Add syntax highlighting for pascal and clojure languages. --- gui/package-lock.json | 56 ++++++++++--------- gui/package.json | 1 + .../markdown/StyledMarkdownPreview.tsx | 13 +++-- 3 files changed, 39 insertions(+), 31 deletions(-) diff --git a/gui/package-lock.json b/gui/package-lock.json index b0918360d..a953d2452 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -30,6 +30,7 @@ "dompurify": "^3.0.6", "downshift": "^7.6.0", "lodash": "^4.17.21", + "lowlight": "^3.3.0", "minisearch": "^7.0.2", "mustache": "^4.2.0", "posthog-js": "^1.130.1", @@ -7688,18 +7689,28 @@ } }, "node_modules/lowlight": { - "version": "1.20.0", - "resolved": "https://registry.npmjs.org/lowlight/-/lowlight-1.20.0.tgz", - "integrity": "sha512-8Ktj+prEb1RoCPkEOrPMYUN/nCggB7qAWe3a7OpMjWQkh3l2RD5wKRQ+o8Q8YuI9RG/xs95waaI/E6ym/7NsTw==", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/lowlight/-/lowlight-3.3.0.tgz", + "integrity": "sha512-0JNhgFoPvP6U6lE/UdVsSq99tn6DhjjpAj5MxG49ewd2mOBVtwWYIT8ClyABhq198aXXODMU6Ox8DrGy/CpTZQ==", + "license": "MIT", "dependencies": { - "fault": "^1.0.0", - "highlight.js": "~10.7.0" + "@types/hast": "^3.0.0", + "devlop": "^1.0.0", + "highlight.js": "~11.11.0" }, "funding": { "type": "github", "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/lowlight/node_modules/highlight.js": { + "version": "11.11.1", + "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-11.11.1.tgz", + "integrity": "sha512-Xwwo44whKBVCYoliBQwaPvtd/2tYFkRQtXDWj1nackaV2JPXx3L0+Jvd8/qCJ2p+ML0/XVkJ2q+Mr+UVdpJK5w==", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/lru-cache": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", @@ -10087,6 +10098,19 @@ "react": ">= 0.14.0" } }, + "node_modules/react-syntax-highlighter/node_modules/lowlight": { + "version": "1.20.0", + "resolved": "https://registry.npmjs.org/lowlight/-/lowlight-1.20.0.tgz", + "integrity": "sha512-8Ktj+prEb1RoCPkEOrPMYUN/nCggB7qAWe3a7OpMjWQkh3l2RD5wKRQ+o8Q8YuI9RG/xs95waaI/E6ym/7NsTw==", + "dependencies": { + "fault": "^1.0.0", + "highlight.js": "~10.7.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/react-tooltip": { "version": "5.28.0", "resolved": "https://registry.npmjs.org/react-tooltip/-/react-tooltip-5.28.0.tgz", @@ -10371,28 +10395,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/rehype-highlight/node_modules/highlight.js": { - "version": "11.9.0", - "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-11.9.0.tgz", - "integrity": "sha512-fJ7cW7fQGCYAkgv4CPfwFHrfd/cLS4Hau96JuJ+ZTOWhjnhoeN1ub1tFmALm/+lW5z4WCAuAV9bm05AP0mS6Gw==", - "engines": { - "node": ">=12.0.0" - } - }, - "node_modules/rehype-highlight/node_modules/lowlight": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/lowlight/-/lowlight-3.1.0.tgz", - "integrity": "sha512-CEbNVoSikAxwDMDPjXlqlFYiZLkDJHwyGu/MfOsJnF3d7f3tds5J3z8s/l9TMXhzfsJCCJEAsD78842mwmg0PQ==", - "dependencies": { - "@types/hast": "^3.0.0", - "devlop": "^1.0.0", - "highlight.js": "~11.9.0" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/rehype-katex": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/rehype-katex/-/rehype-katex-7.0.1.tgz", diff --git a/gui/package.json b/gui/package.json index 6724bd757..e606aebe3 100644 --- a/gui/package.json +++ b/gui/package.json @@ -38,6 +38,7 @@ "dompurify": "^3.0.6", "downshift": "^7.6.0", "lodash": "^4.17.21", + "lowlight": "^3.3.0", "minisearch": "^7.0.2", "mustache": "^4.2.0", "posthog-js": "^1.130.1", diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/markdown/StyledMarkdownPreview.tsx index d968101d0..c21380454 100644 --- a/gui/src/components/markdown/StyledMarkdownPreview.tsx +++ b/gui/src/components/markdown/StyledMarkdownPreview.tsx @@ -1,4 +1,7 @@ import { ctxItemToRifWithContents } from "core/commands/util"; +import clojure from "highlight.js/lib/languages/clojure"; +import Delphi from "highlight.js/lib/languages/Delphi"; +import { common } from "lowlight"; import { memo, useEffect, useMemo } from "react"; import { useRemark } from "react-remark"; import rehypeHighlight, { Options } from "rehype-highlight"; @@ -234,14 +237,16 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( rehypePlugins: [ rehypeKatex as any, {}, - rehypeHighlight as any, + [ + rehypeHighlight, + { + languages: { ...common, clojure, Delphi}, + } as Options, + ], // Note: An empty obj is the default behavior, but leaving this here for scaffolding to // add unsupported languages in the future. We will need to install the `lowlight` package // to use the `common` language set in addition to unsupported languages. // https://github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md - { - // languages: {}, - } as Options, () => { let codeBlockIndex = 0; return (tree) => {