highlightjs / highlight.js

JavaScript syntax highlighter with language auto-detection and zero dependencies.
https://highlightjs.org/
BSD 3-Clause "New" or "Revised" License
23.79k stars 3.61k forks source link

dos/bat/cmd Disk switch "D:" destroys highlight #4134

Open krilbe opened 1 month ago

krilbe commented 1 month ago

Describe the issue If the code snippet contains a disk switch line, e.g. "D:", the subsequent highlight becomes all red. It seems to be connected with the colon. bild

Which language seems to have the issue? "dos"

Seems to be the same with tags "bat" and "cmd".

Seems to work the same with and without space between ``` and the language tag.

Here in GitHub it seems to work correctly with tag "bat", see below under "Expected behavior".

Are you using highlight or highlightAuto? Not sure. I was using this in an Azure DevOps Wiki page.

Sample Code to Reproduce

triplebacktick dos
rem This highlight works.
copy file.txt other.txt 
rem After next line it becomes all red.
D:
cd "D:\Folder"
md Tmp
del Tmp\*.* /q
triplebacktick

Expected behavior The highlight should work normally even after a disk switch command, as here in GitHub:

rem This highlight works.
copy file.txt other.txt 
rem After next line it becomes all red.
D:
cd "D:\Folder"
md Tmp
del Tmp\*.* /q

Additional context Found and tested in an Azure DevOps Wiki page, which seems to point to this repo in the docs: https://learn.microsoft.com/en-us/azure/devops/project/wiki/markdown-guidance?view=azure-devops#code-highlighting

the-dg04 commented 1 month ago

Hey, ive found a potential solution to your problem and linked a PR for it.

After fix: image