From 822a7a4f9d0b76aa4aa36faa5bf0cec50b457fb7 Mon Sep 17 00:00:00 2001 From: megyerikenez Date: Wed, 14 Jan 2026 15:31:16 +0100 Subject: [PATCH 1/3] new language: Add batch script support --- src/languages/batch.js | 61 ++++++++++++++++++++++++++++ test/detect/batch/default.txt | 2 + test/markup/batch/default.expect.txt | 43 ++++++++++++++++++++ test/markup/batch/default.txt | 43 ++++++++++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 src/languages/batch.js create mode 100644 test/detect/batch/default.txt create mode 100644 test/markup/batch/default.expect.txt create mode 100644 test/markup/batch/default.txt diff --git a/src/languages/batch.js b/src/languages/batch.js new file mode 100644 index 0000000000..c72fc9ea1f --- /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", + "cmd", + "dos" + ], + 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 From c3c39081feb02dbd9d26c508696112c6429ace26 Mon Sep 17 00:00:00 2001 From: megyerikenez Date: Thu, 15 Jan 2026 10:13:23 +0100 Subject: [PATCH 2/3] nit fixes --- src/languages/batch.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/languages/batch.js b/src/languages/batch.js index c72fc9ea1f..1811e56587 100644 --- a/src/languages/batch.js +++ b/src/languages/batch.js @@ -2,7 +2,7 @@ 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) +Description: Syntax highlighting for Windows batch files and scripts eg.(.bat, .batch, .cmd) Category: common, scripting */ @@ -12,8 +12,8 @@ export default function(hljs) { name: "Batch file", aliases: [ "bat", - "cmd", - "dos" + "batch", + "cmd" ], case_insensitive: true, keywords: { From a55218419b30ea0664484af139f7a084b9e48e46 Mon Sep 17 00:00:00 2001 From: megyerikenez Date: Mon, 16 Mar 2026 19:22:10 +0100 Subject: [PATCH 3/3] feat(batch): add Batch file language support --- CHANGES.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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