From 341726707fb0435dfd618b72f6c60ccdb096e46e Mon Sep 17 00:00:00 2001 From: Giridhar Nair Date: Tue, 18 Apr 2023 16:13:04 -0500 Subject: [PATCH] Improved upload file language detection --- src/DocsGen.jsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/DocsGen.jsx b/src/DocsGen.jsx index 09bd7a2..6207ec1 100644 --- a/src/DocsGen.jsx +++ b/src/DocsGen.jsx @@ -3,7 +3,6 @@ import { Editor } from '@monaco-editor/react'; import { Prism as PrismSyntaxHighlighter } from 'react-syntax-highlighter'; import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism'; import classNames from 'classnames'; -import detectLang from 'lang-detector'; import { Tooltip } from 'react-tippy'; import 'react-tippy/dist/tippy.css' import flourite from 'flourite'; @@ -90,9 +89,11 @@ function DocsGen () { } function handleEditorChange (newValue) { - if (newValue.includes("Input your raw code here:")) + if (newValue.includes("Input your raw code here:")) { clearOnChange(); - getLanguage(newValue); + } else { + getLanguage(newValue); + } } function getLanguage (value) { @@ -107,13 +108,15 @@ function DocsGen () { } function clearOnChange () { - setValue('') + setValue(''); + setLanguage("Unknown"); } function resetButtonClick () { setResponse('Your altered code will appear here'); setValue('Input your raw code here:'); setStatus('Generate Documentation'); + setLanguage("Unknown"); fileInputRef.current.value = null; }; @@ -202,6 +205,7 @@ function DocsGen () { const file = event.target.files[0]; const reader = new FileReader(); reader.onload = (event) => { + handleEditorChange(event.target.result); setValue(event.target.result); setResponse("Your altered code will appear here"); };