From 09659be0023cdcb539ea26f1e8bbdd3f6dffc6ac Mon Sep 17 00:00:00 2001 From: Daniel Avila Date: Sat, 11 Mar 2023 10:28:46 -0500 Subject: [PATCH] fix: unsupported lang handler in client --- client/src/components/Messages/Highlight.jsx | 8 +- client/src/utils/languages.js | 318 +++++++++++++++++++ 2 files changed, 323 insertions(+), 3 deletions(-) create mode 100644 client/src/utils/languages.js diff --git a/client/src/components/Messages/Highlight.jsx b/client/src/components/Messages/Highlight.jsx index 81a9a9e582..e17228df10 100644 --- a/client/src/components/Messages/Highlight.jsx +++ b/client/src/components/Messages/Highlight.jsx @@ -1,16 +1,18 @@ import React, { useState, useEffect } from 'react'; import hljs from 'highlight.js'; +import languages from '~/utils/languages'; export default function Highlight({language, code}) { const [highlightedCode, setHighlightedCode] = useState(code); + const lang = languages.has(language) ? language : 'shell'; useEffect(() => { - setHighlightedCode(hljs.highlight(code, { language }).value); - }, [code, language]); + setHighlightedCode(hljs.highlight(code, { language: lang }).value); + }, [code, lang]); return (
-      
+      
     
); } \ No newline at end of file diff --git a/client/src/utils/languages.js b/client/src/utils/languages.js new file mode 100644 index 0000000000..443a81a753 --- /dev/null +++ b/client/src/utils/languages.js @@ -0,0 +1,318 @@ +const languages = new Set([ + 'adoc', + 'apacheconf', + 'arm', + 'as', + 'asc', + 'atom', + 'bat', + 'bf', + 'bind', + 'c++', + 'capnp', + 'cc', + 'clj', + 'cls', + 'cmake.in', + 'cmd', + 'coffee', + 'console', + 'cr', + 'craftcms', + 'crm', + 'cs', + 'cson', + 'cts', + 'cxx', + 'dfm', + 'docker', + 'dst', + 'erl', + 'f90', + 'f95', + 'fs', + 'gawk', + 'gemspec', + 'gms', + 'golang', + 'gololang', + 'gss', + 'gyp', + 'h', + 'h++', + 'hbs', + 'hh', + 'hpp', + 'hs', + 'html', + 'html.handlebars', + 'html.hbs', + 'https', + 'hx', + 'hxx', + 'hylang', + 'i7', + 'iced', + 'ino', + 'instances', + 'irb', + 'jinja', + 'js', + 'jsp', + 'jsx', + 'julia-repl', + 'kdb', + 'kt', + 'lassoscript', + 'ls', + 'ls', + 'mak', + 'make', + 'mawk', + 'md', + 'mipsasm', + 'mk', + 'mkd', + 'mkdown', + 'ml', + 'ml', + 'mm', + 'mma', + 'moon', + 'mts', + 'nawk', + 'nc', + 'nginxconf', + 'nimrod', + 'objc', + 'obj-c', + 'obj-c++', + 'objective-c++', + 'osascript', + 'pas', + 'pascal', + 'patch', + 'pcmk', + 'pf.conf', + 'pl', + 'plist', + 'pm', + 'podspec', + 'postgres', + 'postgresql', + 'pp', + 'ps', + 'ps1', + 'py', + 'pycon', + 'rb', + 're', + 'rs', + 'rss', + 'sas', + 'scad', + 'sci', + 'sh', + 'st', + 'stanfuncs', + 'step', + 'stp', + 'styl', + 'svg', + 'tao', + 'text', + 'thor', + 'tk', + 'toml', + 'ts', + 'tsx', + 'txt', + 'v', + 'vb', + 'vbs', + 'wl', + 'x++', + 'xhtml', + 'xjb', + 'xls', + 'xlsx', + 'xpath', + 'xq', + 'xsd', + 'xsl', + 'yaml', + 'zep', + 'zone', + 'zsh', + '1c', + 'abnf', + 'accesslog', + 'actionscript', + 'ada', + 'angelscript', + 'apache', + 'applescript', + 'arcade', + 'arduino', + 'armasm', + 'asciidoc', + 'aspectj', + 'autohotkey', + 'autoit', + 'avrasm', + 'awk', + 'axapta', + 'bash', + 'basic', + 'bnf', + 'brainfuck', + 'c', + 'cal', + 'capnproto', + 'clojure', + 'cmake', + 'coffeescript', + 'coq', + 'cos', + 'cpp', + 'crmsh', + 'crystal', + 'csharp', + 'csp', + 'css', + 'd', + 'dart', + 'diff', + 'django', + 'dns', + 'dockerfile', + 'dos', + 'dpr', + 'dsconfig', + 'dts', + 'dust', + 'ebnf', + 'elixir', + 'elm', + 'erlang', + 'excel', + 'fix', + 'fortran', + 'fsharp', + 'gams', + 'gauss', + 'gcode', + 'gherkin', + 'glsl', + 'go', + 'golo', + 'gradle', + 'graph', + 'graphql', + 'groovy', + 'haml', + 'handlebars', + 'haskell', + 'haxe', + 'http', + 'hy', + 'inform7', + 'ini', + 'irpf90', + 'java', + 'javascript', + 'json', + 'julia', + 'k', + 'kotlin', + 'lasso', + 'ldif', + 'leaf', + 'less', + 'lisp', + 'livecodeserver', + 'livescript', + 'lua', + 'makefile', + 'markdown', + 'mathematica', + 'matlab', + 'maxima', + 'mel', + 'mercury', + 'mips', + 'mizar', + 'mojolicious', + 'monkey', + 'moonscript', + 'n1ql', + 'nginx', + 'nim', + 'nix', + 'nsis', + 'objectivec', + 'ocaml', + 'openscad', + 'oxygene', + 'p21', + 'parser3', + 'perl', + 'pf', + 'pgsql', + 'php', + 'plaintext', + 'pony', + 'powershell', + 'processing', + 'profile', + 'prolog', + 'properties', + 'protobuf', + 'puppet', + 'python', + 'python-repl', + 'qml', + 'r', + 'reasonml', + 'rib', + 'rsl', + 'ruby', + 'ruleslanguage', + 'rust', + 'SAS', + 'scala' , + 'scheme', + 'scilab', + 'scss', + 'shell', + 'smali', + 'smalltalk', + 'sml', + 'sql', + 'stan', + 'stata', + 'stylus', + 'subunit', + 'swift', + 'tap', + 'tcl', + 'tex', + 'thrift', + 'tp', + 'twig', + 'typescript', + 'vala', + 'vbnet', + 'vbscript', + 'verilog', + 'vhdl', + 'vim', + 'x86asm', + 'xl', + 'xml', + 'xquery', + 'yml', + 'zephir', +]); + +module.exports = languages; \ No newline at end of file