Skip to content

Commit

Permalink
Merge branch 'main' into fix-ts-params-types
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel authored Nov 15, 2023
2 parents e8f7519 + 4fc7a0c commit e0ab97c
Show file tree
Hide file tree
Showing 27 changed files with 622 additions and 305 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
- name: Publish highlight.js to NPM
id: publish
uses: JS-DevTools/npm-publish@v2
uses: JS-DevTools/npm-publish@v3
with:
check-version: true
token: ${{ secrets.NPM_TOKEN }}
Expand Down Expand Up @@ -112,7 +112,7 @@ jobs:
- name: Publish cdn-assets to NPM
id: publish_cdn
uses: JS-DevTools/npm-publish@v2
uses: JS-DevTools/npm-publish@v3
with:
check-version: true
token: ${{ secrets.NPM_TOKEN }}
Expand Down
25 changes: 24 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,36 @@

Core Grammars:

- fix(cpp) not all kinds of number literals are highlighted correctly [Lê Duy Quang][]
- fix(css) fix overly greedy pseudo class matching [Bradley Mackey][]
- enh(arcade) updated to ArcGIS Arcade version 1.24 [Kristian Ekenes][]
- fix(typescript): params types [Mohamed Ali][]
- fix(rust) fix escaped double quotes in string [Mohamed Ali][]
- fix(yaml) fix for yaml with keys having brackets highlighted incorrectly [Aneesh Kulkarni][]
- fix(bash) fix # within token being detected as the start of a comment [Felix Uhl][]
- fix(python) fix `or` conflicts with string highlighting [Mohamed Ali][]

New Grammars:

- added 3rd party CODEOWNERS grammar to SUPPORTED_LANGUAGES [nataliia-radina][]
- added 3rd party Luau grammar to SUPPORTED_LANGUAGES [Robloxian Demo][]
- added 3rd party ReScript grammar to SUPPORTED_LANGUAGES [Paul Tsnobiladzé][]

Developer Tool:

- enh(tools): order CSS options picklist [David Schach][]
- enh(tools): remove duplicate CSS options [David Schach][]

[Lê Duy Quang]: https://github.com/leduyquang753
[Mohamed Ali]: https://github.com/MohamedAli00949
[Bradley Mackey]: https://github.com/bradleymackey
[Kristian Ekenes]: https://github.com/ekenes
[Mohamed Ali]: https://github.com/MohamedAli00949
[Aneesh Kulkarni]: https://github.com/aneesh98
[Bruno Meneguele]: https://github.com/bmeneg
[Felix Uhl]: https://github.com/iFreilicht
[nataliia-radina]: https://github.com/Nataliia-Radina
[Robloxian Demo]: https://github.com/RobloxianDemo
[Paul Tsnobiladzé]: https://github.com/tsnobip


## Version 11.9.0
Expand Down
5 changes: 4 additions & 1 deletion SUPPORTED_LANGUAGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ The table below shows the full list of languages (and corresponding classes/alia
| Cache Object Script | cos, cls | |
| Candid | candid, did | [highlightjs-motoko](https://github.com/rvanasa/highlightjs-motoko) |
| CMake | cmake, cmake.in | |
| COBOL | cobol, standard-cobol | [highlightjs-cobol](https://github.com/otterkit/highlightjs-cobol) |
| COBOL | cobol, standard-cobol | [highlightjs-cobol](https://github.com/otterkit/highlightjs-cobol) |
| CODEOWNERS | codeowners | [highlightjs-codeowners](https://github.com/highlightjs/highlightjs-codeowners) |
| Coq | coq | |
| CSP | csp | |
| CSS | css | |
Expand Down Expand Up @@ -129,6 +130,7 @@ The table below shows the full list of languages (and corresponding classes/alia
| LiveScript | livescript, ls | |
| LookML | lookml | [highlightjs-lookml](https://github.com/spectacles-ci/highlightjs-lookml) |
| Lua | lua | |
| Luau | luau | [highlightjs-luau](https://github.com/highlightjs/highlightjs-luau) |
| Macaulay2 | macaulay2 | [highlightjs-macaulay2](https://github.com/d-torrance/highlightjs-macaulay2) |
| Makefile | makefile, mk, mak, make | |
| Markdown | markdown, md, mkdown, mkd | |
Expand Down Expand Up @@ -188,6 +190,7 @@ The table below shows the full list of languages (and corresponding classes/alia
| Rebol & Red | redbol, rebol, red, red-system | [highlightjs-redbol](https://github.com/oldes/highlightjs-redbol) |
| RenderMan RIB | rib | |
| RenderMan RSL | rsl | |
| ReScript | rescript, res | [highlightjs-rescript](https://github.com/tsnobip/highlightjs-rescript) |
| RiScript | risc, riscript | [highlightjs-riscript](https://github.com/highlightjs/highlightjs-riscript) |
| RISC-V Assembly | riscv, riscvasm | [highlightjs-riscvasm](https://github.com/highlightjs/highlightjs-riscvasm) |
| Roboconf | graph, instances | |
Expand Down
14 changes: 13 additions & 1 deletion src/languages/bash.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ export default function(hljs) {
end: /\)/,
contains: [ hljs.BACKSLASH_ESCAPE ]
};
const COMMENT = hljs.inherit(
hljs.COMMENT(),
{
match: [
/(^|\s)/,
/#.*$/
],
scope: {
2: 'comment'
}
}
);
const HERE_DOC = {
begin: /<<-?\s*(?=\w+)/,
starts: { contains: [
Expand Down Expand Up @@ -376,7 +388,7 @@ export default function(hljs) {
hljs.SHEBANG(), // to catch unknown shells but still highlight the shebang
FUNCTION,
ARITHMETIC,
hljs.HASH_COMMENT_MODE,
COMMENT,
HERE_DOC,
PATH_MODE,
QUOTE_STRING,
Expand Down
41 changes: 38 additions & 3 deletions src/languages/cpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,44 @@ export default function(hljs) {
const NUMBERS = {
className: 'number',
variants: [
{ begin: '\\b(0b[01\']+)' },
{ begin: '(-?)\\b([\\d\']+(\\.[\\d\']*)?|\\.[\\d\']+)((ll|LL|l|L)(u|U)?|(u|U)(ll|LL|l|L)?|f|F|b|B)' },
{ begin: '(-?)(\\b0[xX][a-fA-F0-9\']+|(\\b[\\d\']+(\\.[\\d\']*)?|\\.[\\d\']+)([eE][-+]?[\\d\']+)?)' }
// Floating-point literal.
{ begin:
"[+-]?(?:" // Leading sign.
// Decimal.
+ "(?:"
+"[0-9](?:'?[0-9])*\\.(?:[0-9](?:'?[0-9])*)?"
+ "|\\.[0-9](?:'?[0-9])*"
+ ")(?:[Ee][+-]?[0-9](?:'?[0-9])*)?"
+ "|[0-9](?:'?[0-9])*[Ee][+-]?[0-9](?:'?[0-9])*"
// Hexadecimal.
+ "|0[Xx](?:"
+"[0-9A-Fa-f](?:'?[0-9A-Fa-f])*(?:\\.(?:[0-9A-Fa-f](?:'?[0-9A-Fa-f])*)?)?"
+ "|\\.[0-9A-Fa-f](?:'?[0-9A-Fa-f])*"
+ ")[Pp][+-]?[0-9](?:'?[0-9])*"
+ ")(?:" // Literal suffixes.
+ "[Ff](?:16|32|64|128)?"
+ "|(BF|bf)16"
+ "|[Ll]"
+ "|" // Literal suffix is optional.
+ ")"
},
// Integer literal.
{ begin:
"[+-]?\\b(?:" // Leading sign.
+ "0[Bb][01](?:'?[01])*" // Binary.
+ "|0[Xx][0-9A-Fa-f](?:'?[0-9A-Fa-f])*" // Hexadecimal.
+ "|0(?:'?[0-7])*" // Octal or just a lone zero.
+ "|[1-9](?:'?[0-9])*" // Decimal.
+ ")(?:" // Literal suffixes.
+ "[Uu](?:LL?|ll?)"
+ "|[Uu][Zz]?"
+ "|(?:LL?|ll?)[Uu]?"
+ "|[Zz][Uu]"
+ "|" // Literal suffix is optional.
+ ")"
// Note: there are user-defined literal suffixes too, but perhaps having the custom suffix not part of the
// literal highlight actually makes it stand out more.
}
],
relevance: 0
};
Expand Down
73 changes: 53 additions & 20 deletions src/languages/perl.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function(hljs) {
'chown',
'chr',
'chroot',
'class',
'close',
'closedir',
'connect',
Expand Down Expand Up @@ -55,6 +56,7 @@ export default function(hljs) {
'exit',
'exp',
'fcntl',
'field',
'fileno',
'flock',
'for',
Expand Down Expand Up @@ -114,6 +116,7 @@ export default function(hljs) {
'lt',
'ma',
'map',
'method',
'mkdir',
'msgctl',
'msgget',
Expand Down Expand Up @@ -258,19 +261,45 @@ export default function(hljs) {
end: /\}/
// contains defined later
};
const VAR = { variants: [
{ begin: /\$\d/ },
{ begin: regex.concat(
/[$%@](\^\w\b|#\w+(::\w+)*|\{\w+\}|\w+(::\w*)*)/,
// negative look-ahead tries to avoid matching patterns that are not
// Perl at all like $ident$, @ident@, etc.
`(?![A-Za-z])(?![@$%])`
) },
{
begin: /[$%@][^\s\w{]/,
relevance: 0
}
] };
const ATTR = {
scope: 'attr',
match: /\s+:\s*\w+(\s*\(.*?\))?/,
};
const VAR = {
scope: 'variable',
variants: [
{ begin: /\$\d/ },
{ begin: regex.concat(
/[$%@](\^\w\b|#\w+(::\w+)*|\{\w+\}|\w+(::\w*)*)/,
// negative look-ahead tries to avoid matching patterns that are not
// Perl at all like $ident$, @ident@, etc.
`(?![A-Za-z])(?![@$%])`
)
},
{
// Only $= is a special Perl variable and one can't declare @= or %=.
begin: /[$%@][^\s\w{=]|\$=/,
relevance: 0
}
],
contains: [ ATTR ],
};
const NUMBER = {
className: 'number',
variants: [
// decimal numbers:
// include the case where a number starts with a dot (eg. .9), and
// the leading 0? avoids mixing the first and second match on 0.x cases
{ match: /0?\.[0-9][0-9_]+\b/ },
// include the special versioned number (eg. v5.38)
{ match: /\bv?(0|[1-9][0-9_]*(\.[0-9_]+)?|[1-9][0-9_]*)\b/ },
// non-decimal numbers:
{ match: /\b0[0-7][0-7_]*\b/ },
{ match: /\b0x[0-9a-fA-F][0-9a-fA-F_]*\b/ },
{ match: /\b0b[0-1][0-1_]*\b/ },
],
relevance: 0
}
const STRING_CONTAINS = [
hljs.BACKSLASH_ESCAPE,
SUBST,
Expand Down Expand Up @@ -385,11 +414,7 @@ export default function(hljs) {
}
]
},
{
className: 'number',
begin: '(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b',
relevance: 0
},
NUMBER,
{ // regexp container
begin: '(\\/\\/|' + hljs.RE_STARTERS_RE + '|\\b(split|return|print|reverse|grep)\\b)\\s*',
keywords: 'split return print reverse grep',
Expand Down Expand Up @@ -431,11 +456,19 @@ export default function(hljs) {
},
{
className: 'function',
beginKeywords: 'sub',
beginKeywords: 'sub method',
end: '(\\s*\\(.*?\\))?[;{]',
excludeEnd: true,
relevance: 5,
contains: [ hljs.TITLE_MODE ]
contains: [ hljs.TITLE_MODE, ATTR ]
},
{
className: 'class',
beginKeywords: 'class',
end: '[;{]',
excludeEnd: true,
relevance: 5,
contains: [ hljs.TITLE_MODE, ATTR, NUMBER ]
},
{
begin: '-\\w\\b',
Expand Down
1 change: 1 addition & 0 deletions src/languages/python.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ export default function(hljs) {
beginKeywords: "if",
relevance: 0
},
{ match: /\bor\b/, scope: "keyword" },
STRING,
COMMENT_TYPE,
hljs.HASH_COMMENT_MODE,
Expand Down
5 changes: 4 additions & 1 deletion src/languages/rust.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ export default function(hljs) {
{
className: 'string',
begin: /"/,
end: /"/
end: /"/,
contains: [
hljs.BACKSLASH_ESCAPE
]
}
]
},
Expand Down
11 changes: 6 additions & 5 deletions src/languages/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ export default function(hljs) {
const KEY = {
className: 'attr',
variants: [
{ begin: '\\w[\\w :\\/.-]*:(?=[ \t]|$)' },
{ // double quoted keys
begin: '"\\w[\\w :\\/.-]*":(?=[ \t]|$)' },
{ // single quoted keys
begin: '\'\\w[\\w :\\/.-]*\':(?=[ \t]|$)' }
// added brackets support
{ begin: /\w[\w :()\./-]*:(?=[ \t]|$)/ },
{ // double quoted keys - with brackets
begin: /"\w[\w :()\./-]*":(?=[ \t]|$)/ },
{ // single quoted keys - with brackets
begin: /'\w[\w :()\./-]*':(?=[ \t]|$)/ },
]
};

Expand Down
3 changes: 3 additions & 0 deletions test/markup/bash/not-comments.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<span class="hljs-built_in">echo</span> asdf#qwert yuiop

<span class="hljs-built_in">echo</span> asdf <span class="hljs-comment">#qwert yuiop</span>
3 changes: 3 additions & 0 deletions test/markup/bash/not-comments.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
echo asdf#qwert yuiop

echo asdf #qwert yuiop
64 changes: 54 additions & 10 deletions test/markup/cpp/number-literals.expect.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,55 @@
<span class="hljs-comment">/* digit separators */</span>
<span class="hljs-type">int</span> number = <span class="hljs-number">2&#x27;555&#x27;555&#x27;555</span>; <span class="hljs-comment">// digit separators</span>
<span class="hljs-type">float</span> exponentFloat = <span class="hljs-number">.123&#x27;456e3&#x27;000</span>; <span class="hljs-comment">// digit separators in floats</span>
<span class="hljs-type">float</span> suffixed = <span class="hljs-number">3.000&#x27;001&#x27;234f</span> <span class="hljs-comment">// digit separators in suffixed numbers</span>
<span class="hljs-type">char</span> word[] = { <span class="hljs-string">&#x27;3&#x27;</span>, <span class="hljs-string">&#x27;\0&#x27;</span> }; <span class="hljs-comment">// make sure digit separators don&#x27;t mess up chars</span>
<span class="hljs-type">float</span> negative = <span class="hljs-number">-123.0f</span>; <span class="hljs-comment">// negative floating point numbers</span>
<span class="hljs-comment">/* Floating-point literals. */</span>
<span class="hljs-comment">// Decimal.</span>
<span class="hljs-number">1.</span>
<span class="hljs-number">+12.</span>
<span class="hljs-number">-1&#x27;234.</span>
<span class="hljs-number">1.2</span>
<span class="hljs-number">1.234&#x27;5</span>
<span class="hljs-number">1&#x27;234.567&#x27;8</span>
<span class="hljs-number">1&#x27;234.567&#x27;8e-9</span>
<span class="hljs-number">1&#x27;234.567&#x27;8E9&#x27;0</span>
<span class="hljs-number">1234e56</span>
<span class="hljs-number">1&#x27;234e5&#x27;6</span>
<span class="hljs-comment">// Hexadecimal.</span>
<span class="hljs-number">0x1p2</span>
<span class="hljs-number">+0x1.p2</span>
<span class="hljs-number">-0X1A.P2</span>
<span class="hljs-number">0x1A&#x27;2B3C.p4</span>
<span class="hljs-number">0x1.Ap2</span>
<span class="hljs-number">0x1A.2B3C&#x27;4Dp+5</span>
<span class="hljs-number">0x1A&#x27;2b3C.4D5e&#x27;6Fp7&#x27;8</span>
<span class="hljs-comment">// Literal suffixes.</span>
<span class="hljs-number">1.F</span> <span class="hljs-number">1.F16</span> <span class="hljs-number">1.F32</span> <span class="hljs-number">1.f64</span> <span class="hljs-number">1.f128</span>
<span class="hljs-number">2.BF16</span> <span class="hljs-number">2.bf16</span>
<span class="hljs-number">0X3&#x27;4.P5L</span> <span class="hljs-number">0x3&#x27;4.p5l</span>

<span class="hljs-comment">/* literal suffixes: these are to be highlighted as numbers */</span>
<span class="hljs-number">90ll</span> <span class="hljs-number">90LL</span> <span class="hljs-number">90u</span> <span class="hljs-number">90U</span> <span class="hljs-number">90l</span> <span class="hljs-number">90L</span>
<span class="hljs-number">90ul</span> <span class="hljs-number">90ul</span> <span class="hljs-number">90Ul</span> <span class="hljs-number">90UL</span> <span class="hljs-number">90lu</span> <span class="hljs-number">90lU</span> <span class="hljs-number">90Lu</span> <span class="hljs-number">90LU</span>
<span class="hljs-number">90ull</span> <span class="hljs-number">90uLL</span> <span class="hljs-number">90Ull</span> <span class="hljs-number">90ULL</span> <span class="hljs-number">90llu</span> <span class="hljs-number">90llU</span> <span class="hljs-number">90LLu</span> <span class="hljs-number">90LLU</span>
<span class="hljs-comment">/* Integer literals. */</span>
<span class="hljs-comment">// Binary.</span>
<span class="hljs-number">+0b1</span>
<span class="hljs-number">0B01</span>
<span class="hljs-number">-0b10&#x27;1011</span>
<span class="hljs-comment">// Hexadecimal.</span>
<span class="hljs-number">+0x1</span>
<span class="hljs-number">0X1A</span>
<span class="hljs-number">-0x1A&#x27;2b3C</span>
<span class="hljs-comment">// Octal.</span>
<span class="hljs-number">+01</span>
<span class="hljs-number">012</span>
<span class="hljs-number">-0123&#x27;4567</span>
<span class="hljs-comment">// Decimal.</span>
<span class="hljs-number">0</span>
<span class="hljs-number">+1</span>
<span class="hljs-number">12</span>
<span class="hljs-number">-123&#x27;456&#x27;789</span>
<span class="hljs-comment">// Literal suffixes.</span>
<span class="hljs-number">0B1U</span> <span class="hljs-number">0b1u</span>
<span class="hljs-number">0X2L</span> <span class="hljs-number">0x2l</span>
<span class="hljs-number">03LL</span> <span class="hljs-number">03ll</span>
<span class="hljs-number">4UL</span> <span class="hljs-number">4Ul</span> <span class="hljs-number">4uL</span> <span class="hljs-number">4ul</span>
<span class="hljs-number">5LU</span> <span class="hljs-number">5Lu</span> <span class="hljs-number">5lU</span> <span class="hljs-number">5lu</span>
<span class="hljs-number">6ULL</span> <span class="hljs-number">6Ull</span> <span class="hljs-number">6uLL</span> <span class="hljs-number">6ull</span>
<span class="hljs-number">7LLU</span> <span class="hljs-number">7LLu</span> <span class="hljs-number">7llU</span> <span class="hljs-number">7llu</span>
<span class="hljs-number">8ZU</span> <span class="hljs-number">8Zu</span> <span class="hljs-number">8zU</span> <span class="hljs-number">8zu</span>
<span class="hljs-number">9&#x27;0UZ</span> <span class="hljs-number">9&#x27;0Uz</span> <span class="hljs-number">9&#x27;0uZ</span> <span class="hljs-number">9&#x27;0uz</span>

<span class="hljs-type">char</span> word[] = { <span class="hljs-string">&#x27;3&#x27;</span>, <span class="hljs-string">&#x27;\0&#x27;</span> }; <span class="hljs-comment">// Make sure digit separators don&#x27;t mess up chars.</span>
Loading

0 comments on commit e0ab97c

Please sign in to comment.