diff --git a/changes/27463-add-script-syntax-highlighting b/changes/27463-add-script-syntax-highlighting new file mode 100644 index 0000000000..c18ad6ffb2 --- /dev/null +++ b/changes/27463-add-script-syntax-highlighting @@ -0,0 +1 @@ +- Added shell and Powershell syntax highlighting when editing scripts \ No newline at end of file diff --git a/frontend/components/Editor/Editor.tsx b/frontend/components/Editor/Editor.tsx index e471b8ec74..a68604257a 100644 --- a/frontend/components/Editor/Editor.tsx +++ b/frontend/components/Editor/Editor.tsx @@ -2,6 +2,8 @@ import classnames from "classnames"; import TooltipWrapper from "components/TooltipWrapper"; import React, { ReactNode } from "react"; import AceEditor from "react-ace"; +import "ace-builds/src-noconflict/mode-sh"; +import "ace-builds/src-noconflict/mode-powershell"; import { IAceEditor } from "react-ace/lib/types"; const baseClass = "editor"; @@ -30,6 +32,9 @@ interface IEditorProps { * @default "editor" */ name?: string; + /** The syntax highlighting mode to use. + */ + mode?: string; /** Include correct styles as a form field. * @default false */ @@ -58,6 +63,7 @@ const Editor = ({ readOnly = false, wrapEnabled = false, name = "editor", + mode, isFormField = false, maxLines = 20, className, @@ -118,6 +124,7 @@ const Editor = ({
{renderLabel()} ; } + // Set editing mode based on the file extension. + const mode = scriptName.match(/\.sh$/) ? "sh" : "powershell"; + return ( <>