diff --git a/CHANGES.md b/CHANGES.md index b1413c29a5..05d1811ace 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,14 @@ +## Version 11.11.3 + +New Grammars: + +- added Batch file language support [Kenez Megyeri][] + +CONTRIBUTORS + +[Kenez Megyeri]: https://github.com/kenez-megyeri + + ## Version 11.11.2 Themes: @@ -55,6 +66,7 @@ CONTRIBUTORS [te-ing]: https://github.com/te-ing [Anthony Martin]: https://github.com/anthony-c-martin [NriotHrreion]: https://github.com/NriotHrreion +[Kenez Megyeri]: https://github.com/kenez-megyeri ## Version 11.11.1 diff --git a/src/languages/batch.js b/src/languages/batch.js new file mode 100644 index 0000000000..1811e56587 --- /dev/null +++ b/src/languages/batch.js @@ -0,0 +1,61 @@ +/* +Language: Batch +Author: Kenez Megyeri +Website: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands +Description: Syntax highlighting for Windows batch files and scripts eg.(.bat, .batch, .cmd) +Category: common, scripting +*/ + +/** @type LanguageFn */ +export default function(hljs) { + return { + name: "Batch file", + aliases: [ + "bat", + "batch", + "cmd" + ], + case_insensitive: true, + keywords: { + built_in: + "append assoc at attrib break cacls cd chcp chdir chkdsk chkntfs cls cmd color comp compact convert copy date del dir diskcomp diskcopy doskey echo endlocal erase fc find findstr format ftype graftabl help keyb label md mkdir mode more move path pause popd print prompt pushd rd recover ren rename replace restore rmdir set setlocal shift sort start subst time title tree type ver verify vol xcopy rem ping netsh taskkill tasklist reg regedit sc net ipconfig systeminfo wmic powershell curl wget timeout robocopy icacls takeown cipher schtasks gpupdate whoami hostname goto call exit if else for do while in defined errorlevel cmdextversion not", + operator: "EQU NEQ LSS LEQ GTR GEQ", + }, + contains: [ + { + className: "comment", + begin: /^\s*rem\s/i, + end: /$/, + relevance: 10, + }, + { + className: "comment", + begin: /::/, + end: /$/, + }, + { + className: "string", + begin: /"/, + end: /"/, + contains: [ + { + className: "variable", + begin: /%\w+%/, + }, + ], + }, + { + className: "number", + begin: /\b\d+\b/, + }, + { + className: "operator", + begin: /[|&><]/, + }, + { + className: "operator", + begin: /\d*(?:>>|>|<|2>&1|2>nul)/, + }, + ], + }; +} diff --git a/test/detect/batch/default.txt b/test/detect/batch/default.txt new file mode 100644 index 0000000000..f6e3e983f0 --- /dev/null +++ b/test/detect/batch/default.txt @@ -0,0 +1,2 @@ +@echo off +echo Hello World diff --git a/test/markup/batch/default.expect.txt b/test/markup/batch/default.expect.txt new file mode 100644 index 0000000000..da0d36bfc5 --- /dev/null +++ b/test/markup/batch/default.expect.txt @@ -0,0 +1,43 @@ +@echo off +rem This is a comment +::This is also a comment + +setlocal enabledelayedexpansion +set name=World +set count=42 + +echo Hello %name%! +echo Count: %count% + +if exist "file.txt" ( + echo File exists +) else ( + echo File does not exist +) + +if not defined myvar ( + echo Variable not defined +) + +for /L %%i in (1,1,5) do ( + echo %%i +) + +dir /s +copy source.txt destination.txt +del oldfile.txt + +cd C:\Users +pushd . +popd + +call :subroutine +exit /b 0 + +:subroutine +echo This is a subroutine +goto :eof + +tasklist +ipconfig /all +powershell Get-Process diff --git a/test/markup/batch/default.txt b/test/markup/batch/default.txt new file mode 100644 index 0000000000..d541918bdb --- /dev/null +++ b/test/markup/batch/default.txt @@ -0,0 +1,43 @@ +@echo off +rem This is a comment +::This is also a comment + +setlocal enabledelayedexpansion +set name=World +set count=42 + +echo Hello %name%! +echo Count: %count% + +if exist "file.txt" ( + echo File exists +) else ( + echo File does not exist +) + +if not defined myvar ( + echo Variable not defined +) + +for /L %%i in (1,1,5) do ( + echo %%i +) + +dir /s +copy source.txt destination.txt +del oldfile.txt + +cd C:\Users +pushd . +popd + +call :subroutine +exit /b 0 + +:subroutine +echo This is a subroutine +goto :eof + +tasklist +ipconfig /all +powershell Get-Process