Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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
Expand Down
61 changes: 61 additions & 0 deletions src/languages/batch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Language: Batch
Author: Kenez Megyeri <m.kenz99@gmail.com>
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)/,
},
],
};
}
2 changes: 2 additions & 0 deletions test/detect/batch/default.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
echo Hello World
43 changes: 43 additions & 0 deletions test/markup/batch/default.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@<span class="hljs-built_in">echo</span> off
<span class="hljs-comment">rem This is a comment</span>
<span class="hljs-comment">::This is also a comment</span>

<span class="hljs-built_in">setlocal</span> enabledelayedexpansion
<span class="hljs-built_in">set</span> name=World
<span class="hljs-built_in">set</span> count=<span class="hljs-number">42</span>

<span class="hljs-built_in">echo</span> Hello %name%!
<span class="hljs-built_in">echo</span> Count: %count%

<span class="hljs-built_in">if</span> exist <span class="hljs-string">&quot;file.txt&quot;</span> (
<span class="hljs-built_in">echo</span> File exists
) <span class="hljs-built_in">else</span> (
<span class="hljs-built_in">echo</span> File does <span class="hljs-built_in">not</span> exist
)

<span class="hljs-built_in">if</span> <span class="hljs-built_in">not</span> <span class="hljs-built_in">defined</span> myvar (
<span class="hljs-built_in">echo</span> Variable <span class="hljs-built_in">not</span> <span class="hljs-built_in">defined</span>
)

<span class="hljs-built_in">for</span> /L %%i <span class="hljs-built_in">in</span> (<span class="hljs-number">1</span>,<span class="hljs-number">1</span>,<span class="hljs-number">5</span>) <span class="hljs-built_in">do</span> (
<span class="hljs-built_in">echo</span> %%i
)

<span class="hljs-built_in">dir</span> /s
<span class="hljs-built_in">copy</span> source.txt destination.txt
<span class="hljs-built_in">del</span> oldfile.txt

<span class="hljs-built_in">cd</span> C:\Users
<span class="hljs-built_in">pushd</span> .
<span class="hljs-built_in">popd</span>

<span class="hljs-built_in">call</span> :subroutine
<span class="hljs-built_in">exit</span> /b <span class="hljs-number">0</span>

:subroutine
<span class="hljs-built_in">echo</span> This is a subroutine
<span class="hljs-built_in">goto</span> :eof

<span class="hljs-built_in">tasklist</span>
<span class="hljs-built_in">ipconfig</span> /all
<span class="hljs-built_in">powershell</span> Get-Process
43 changes: 43 additions & 0 deletions test/markup/batch/default.txt
Original file line number Diff line number Diff line change
@@ -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