highlightjs / highlight.js

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

fix(gcode): stricter gcode line number matching #4034

Open barthy-koeln opened 2 months ago

barthy-koeln commented 2 months ago

Changes

The current G-CODE syntax is too loose on the "line number" instruction matching.

Example:

N1 M6
N2 SAVE_CONFIG

Rendered as:

<span class="hljs-symbol">N1</span> <span class="hljs-name">M6</span>
<span class="hljs-symbol">N1</span> SAVE_CO<span class="hljs-symbol">NFIG</span>

NFIG is not a line number instruction or symbol. My proposed fix is to strictly match the letter N, followed by one or more digits.


This does not resolve all issues, such as matching N\d+ that is NOT at the start of the line:

SKEW_PROFILE SAVE=GuteN8

Rendered as

SKEW_PROFILE SAVE=Gute<span class="hljs-symbol">N8</span>

I haven't found a straightforward and reliable specification or source listing exactly which optional characters are allowed before line numbers. Unfortunately, I currently don't have the time to dive deeper into ISO specs.

But I think that this a good minimal change that resolves some issues and hopefully doesn't cause others.

Checklist

barthy-koeln commented 2 months ago

I suggest closing this in favor of #4040