Skip to content

Commit

Permalink
Merge branch 'main' into esm-in-cdn
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Jun 11, 2021
2 parents 92b2895 + 40b6a8a commit 47f82c8
Show file tree
Hide file tree
Showing 21 changed files with 208 additions and 57 deletions.
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

Grammars:

- enh(powershell) added `pwsh` alias (#3236) [tebeco][]
- fix(r) fix bug highlighting examples in doc comments [Konrad Rudolph][]
- fix(python) identifiers starting with underscore not highlighted (#3221) [Antoine Lambert][]
- enh(clojure) added `edn` alias (#3213) [Stel Abrego][]
- enh(elixir) much improved regular expression sigil support (#3207) [Josh Goebel][]
- enh(elixir) updated list of keywords (#3212) [Angelika Tyborska][]
- fix(elixir) fixed number detection when numbers start with a zero (#3212) [Angelika Tyborska][]

[Stel Abrego]: https://github.com/stelcodes
[Josh Goebel]: https://github.com/joshgoebel
[Antoine Lambert]: https://github.com/anlambert
[Angelika Tyborska]: https://github.com/angelikatyborska
[Konrad Rudolph]: https://github.com/klmr
[tebeco]: https://github.com/tebeco


## Version 11.0.0

Expand Down
8 changes: 2 additions & 6 deletions src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ const HLJS = function(hljs) {
* @param {string} codeOrLanguageName - the language to use for highlighting
* @param {string | HighlightOptions} optionsOrCode - the code to highlight
* @param {boolean} [ignoreIllegals] - whether to ignore illegal matches, default is to bail
* @param {CompiledMode} [continuation] - current continuation mode, if any
*
* @returns {HighlightResult} Result - an object that represents the result
* @property {string} language - the language name
Expand All @@ -131,16 +130,13 @@ const HLJS = function(hljs) {
* @property {CompiledMode} top - top of the current mode stack
* @property {boolean} illegal - indicates whether any illegal matches were found
*/
function highlight(codeOrLanguageName, optionsOrCode, ignoreIllegals, continuation) {
function highlight(codeOrLanguageName, optionsOrCode, ignoreIllegals) {
let code = "";
let languageName = "";
if (typeof optionsOrCode === "object") {
code = codeOrLanguageName;
ignoreIllegals = optionsOrCode.ignoreIllegals;
languageName = optionsOrCode.language;
// continuation not supported at all via the new API
// eslint-disable-next-line no-undefined
continuation = undefined;
} else {
// old API
logger.deprecated("10.7.0", "highlight(lang, code, ...args) has been deprecated.");
Expand All @@ -166,7 +162,7 @@ const HLJS = function(hljs) {
// in which case we don't even need to call highlight
const result = context.result
? context.result
: _highlight(context.language, context.code, ignoreIllegals, continuation);
: _highlight(context.language, context.code, ignoreIllegals);

result.code = context.code;
// the plugin can change anything in result to suite it
Expand Down
43 changes: 22 additions & 21 deletions src/languages/elixir.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,46 @@ export default function(hljs) {
const ELIXIR_IDENT_RE = '[a-zA-Z_][a-zA-Z0-9_.]*(!|\\?)?';
const ELIXIR_METHOD_RE = '[a-zA-Z_]\\w*[!?=]?|[-+~]@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?';
const KEYWORDS = [
"alias",
"after",
"alias",
"and",
"begin",
"break",
"case",
"catch",
"cond",
"defined",
"defstruct",
"do",
"else",
"end",
"ensure",
"false",
"fn",
"for",
"if",
"import",
"in",
"include",
"module",
"next",
"nil",
"not",
"or",
"quote",
"redo",
"raise",
"receive",
"require",
"retry",
"return",
"self",
"then",
"true",
"reraise",
"rescue",
"try",
"unless",
"until",
"unquote",
"unquote_splicing",
"use",
"when",
"while",
"with|0"
];
const LITERALS = [
"false",
"nil",
"true"
];
const KWS = {
$pattern: ELIXIR_IDENT_RE,
keyword: KEYWORDS
keyword: KEYWORDS,
literal: LITERALS
};
const SUBST = {
className: 'subst',
Expand All @@ -62,7 +62,7 @@ export default function(hljs) {
};
const NUMBER = {
className: 'number',
begin: '(\\b0o[0-7_]+)|(\\b0b[01_]+)|(\\b0x[0-9a-fA-F_]+)|(-?\\b[1-9][0-9_]*(\\.[0-9_]+([eE][-+]?[0-9]+)?)?)',
begin: '(\\b0o[0-7_]+)|(\\b0b[01_]+)|(\\b0x[0-9a-fA-F_]+)|(-?\\b[0-9][0-9_]*(\\.[0-9_]+([eE][-+]?[0-9]+)?)?)',
relevance: 0
};
// TODO: could be tightened
Expand Down Expand Up @@ -218,7 +218,7 @@ export default function(hljs) {
};
const FUNCTION = {
className: 'function',
beginKeywords: 'def defp defmacro',
beginKeywords: 'def defp defmacro defmacrop',
end: /\B\b/, // the mode is ended by the title
contains: [
hljs.inherit(hljs.TITLE_MODE, {
Expand Down Expand Up @@ -272,6 +272,7 @@ export default function(hljs) {

return {
name: 'Elixir',
aliases: ['ex', 'exs'],
keywords: KWS,
contains: ELIXIR_DEFAULT_CONTAINS
};
Expand Down
1 change: 1 addition & 0 deletions src/languages/powershell.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ export default function(hljs) {
return {
name: 'PowerShell',
aliases: [
"pwsh",
"ps",
"ps1"
],
Expand Down
29 changes: 12 additions & 17 deletions src/languages/r.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,15 @@ export default function(hljs) {
// doctags shouldn’t be treated as such. See
// `test/markup/r/roxygen.txt` for an example.
scope: 'doctag',
begin: '@examples',
match: /@examples/,
starts: {
contains: [
{ begin: /\n/ },
{
begin: /#'\s*(?=@[a-zA-Z]+)/,
endsParent: true,
},
{
begin: /#'/,
end: /$/,
excludeBegin: true,
}
]
end: regex.lookahead(regex.either(
// end if another doc comment
/\n^#'\s*(?=@[a-zA-Z]+)/,
// or a line with no comment
/\n^(?!#')/
)),
endsParent: true
}
},
{
Expand All @@ -111,20 +106,20 @@ export default function(hljs) {
{
scope: 'variable',
variants: [
{ begin: IDENT_RE },
{ begin: /`(?:\\.|[^`\\])+`/ }
{ match: IDENT_RE },
{ match: /`(?:\\.|[^`\\])+`/ }
],
endsParent: true
}
]
},
{
scope: 'doctag',
begin: /@[a-zA-Z]+/
match: /@[a-zA-Z]+/
},
{
scope: 'keyword',
begin: /\\[a-zA-Z]+/,
match: /\\[a-zA-Z]+/
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion src/languages/wren.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export default function(hljs) {
// CamelCase
const CLASS_REFERENCE = {
relevance: 0,
match: /[A-Z]+[a-z]+([A-Z]+[a-z]+)*/,
match: /\b[A-Z]+[a-z]+([A-Z]+[a-z]+)*/,
scope: "title.class",
keywords: {
_: CORE_CLASSES
Expand Down
41 changes: 41 additions & 0 deletions test/markup/elixir/conditionals.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<span class="hljs-keyword">case</span> x <span class="hljs-keyword">do</span>
<span class="hljs-number">1</span> -&gt; <span class="hljs-symbol">:one</span>
<span class="hljs-number">2</span> -&gt; <span class="hljs-symbol">:two</span>
n <span class="hljs-keyword">when</span> is_integer(n) -&gt; <span class="hljs-symbol">:more</span>
_ -&gt; <span class="hljs-symbol">:error</span>
<span class="hljs-keyword">end</span>

<span class="hljs-keyword">cond</span> <span class="hljs-keyword">do</span>
x &gt; <span class="hljs-number">30</span> -&gt; <span class="hljs-symbol">:ok</span>
y &lt;= <span class="hljs-number">7</span> -&gt; <span class="hljs-symbol">:maybe</span>
z == <span class="hljs-symbol">:skip</span> -&gt; <span class="hljs-symbol">:ok</span>
<span class="hljs-literal">true</span> -&gt; <span class="hljs-symbol">:error</span>
<span class="hljs-keyword">end</span>

<span class="hljs-keyword">if</span> x &gt; <span class="hljs-number">4</span> <span class="hljs-keyword">do</span>
<span class="hljs-symbol">:ok</span>
<span class="hljs-keyword">end</span>

<span class="hljs-keyword">if</span> x &gt; <span class="hljs-number">4</span>, <span class="hljs-symbol">do:</span> <span class="hljs-symbol">:ok</span>

<span class="hljs-keyword">if</span> x &gt; <span class="hljs-number">4</span> <span class="hljs-keyword">do</span>
<span class="hljs-symbol">:ok</span>
<span class="hljs-keyword">else</span>
<span class="hljs-symbol">:error</span>
<span class="hljs-keyword">end</span>

<span class="hljs-keyword">if</span> x &gt; <span class="hljs-number">4</span>, <span class="hljs-symbol">do:</span> <span class="hljs-symbol">:ok</span>, <span class="hljs-symbol">else:</span> <span class="hljs-symbol">:error</span>

<span class="hljs-keyword">unless</span> y &lt; <span class="hljs-number">50</span> <span class="hljs-keyword">do</span>
<span class="hljs-symbol">:error</span>
<span class="hljs-keyword">end</span>

<span class="hljs-keyword">unless</span> y &lt; <span class="hljs-number">50</span>, <span class="hljs-symbol">do:</span> <span class="hljs-symbol">:error</span>

<span class="hljs-keyword">unless</span> y &lt; <span class="hljs-number">50</span> <span class="hljs-keyword">do</span>
<span class="hljs-symbol">:error</span>
<span class="hljs-keyword">else</span>
<span class="hljs-symbol">:ok</span>
<span class="hljs-keyword">end</span>

<span class="hljs-keyword">unless</span> y &lt; <span class="hljs-number">50</span>, <span class="hljs-symbol">do:</span> <span class="hljs-symbol">:error</span>, <span class="hljs-symbol">else:</span> <span class="hljs-symbol">:ok</span>
41 changes: 41 additions & 0 deletions test/markup/elixir/conditionals.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
case x do
1 -> :one
2 -> :two
n when is_integer(n) -> :more
_ -> :error
end

cond do
x > 30 -> :ok
y <= 7 -> :maybe
z == :skip -> :ok
true -> :error
end

if x > 4 do
:ok
end

if x > 4, do: :ok

if x > 4 do
:ok
else
:error
end

if x > 4, do: :ok, else: :error

unless y < 50 do
:error
end

unless y < 50, do: :error

unless y < 50 do
:error
else
:ok
end

unless y < 50, do: :error, else: :ok
6 changes: 6 additions & 0 deletions test/markup/elixir/function-title.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">f!</span></span>, <span class="hljs-symbol">do:</span> IO.puts <span class="hljs-string">&quot;hello world&quot;</span>

<span class="hljs-function"><span class="hljs-keyword">defp</span> <span class="hljs-title">f?</span></span>, <span class="hljs-symbol">do:</span> <span class="hljs-literal">true</span>

<span class="hljs-function"><span class="hljs-keyword">defmacro</span> <span class="hljs-title">foo</span></span>, <span class="hljs-symbol">do:</span> <span class="hljs-symbol">:ok</span>

<span class="hljs-function"><span class="hljs-keyword">defmacrop</span> <span class="hljs-title">do_foo</span></span>, <span class="hljs-symbol">do:</span> <span class="hljs-symbol">:ok</span>

x = <span class="hljs-number">5</span>
6 changes: 6 additions & 0 deletions test/markup/elixir/function-title.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ end

def f!, do: IO.puts "hello world"

defp f?, do: true

defmacro foo, do: :ok

defmacrop do_foo, do: :ok

x = 5
12 changes: 12 additions & 0 deletions test/markup/elixir/modules.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">User</span></span> <span class="hljs-keyword">do</span>
<span class="hljs-keyword">defstruct</span> [<span class="hljs-symbol">:name</span>, <span class="hljs-symbol">:email</span>, <span class="hljs-symbol">age:</span> <span class="hljs-number">18</span>]
<span class="hljs-keyword">end</span>

<span class="hljs-class"><span class="hljs-keyword">defprotocol</span> <span class="hljs-title">Size</span></span> <span class="hljs-keyword">do</span>
<span class="hljs-variable">@doc</span> <span class="hljs-string">&quot;Calculates the size (and not the length!) of a data structure&quot;</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">size</span></span>(data)
<span class="hljs-keyword">end</span>

<span class="hljs-class"><span class="hljs-keyword">defimpl</span> <span class="hljs-title">Size</span></span>, <span class="hljs-symbol">for:</span> Map <span class="hljs-keyword">do</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">size</span></span>(map), <span class="hljs-symbol">do:</span> map_size(map)
<span class="hljs-keyword">end</span>
12 changes: 12 additions & 0 deletions test/markup/elixir/modules.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule User do
defstruct [:name, :email, age: 18]
end

defprotocol Size do
@doc "Calculates the size (and not the length!) of a data structure"
def size(data)
end

defimpl Size, for: Map do
def size(map), do: map_size(map)
end
7 changes: 7 additions & 0 deletions test/markup/elixir/numbers.expect.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
integer = <span class="hljs-number">1234</span>
integer_with_leading_zero = <span class="hljs-number">01234</span>
integer_zero = <span class="hljs-number">0</span>
big_integer = <span class="hljs-number">1_234_000</span>
neg_integer = <span class="hljs-number">-20_000</span>
float = <span class="hljs-number">2.34</span>
float_with_leading_zero = <span class="hljs-number">0.34</span>
float_zero = <span class="hljs-number">0.0</span>
sci_float = <span class="hljs-number">2.4e23</span>
plus_sci_float = <span class="hljs-number">2.4e+23</span>
small_sci_float = <span class="hljs-number">2.4e-23</span>
cap_sci_float = <span class="hljs-number">2.4E23</span>
binary = <span class="hljs-number">0b1010</span>
binary_with_leading_zero = <span class="hljs-number">0b0010</span>
strange_binary = <span class="hljs-number">0b1010_1010_1010</span>
octal = <span class="hljs-number">0o777</span>
octal_with_leading_zero = <span class="hljs-number">0o077</span>
strange_octal = <span class="hljs-number">0o777_666_555</span>
hex = <span class="hljs-number">0x1ABEF</span>
hex_with_leading_zero = <span class="hljs-number">0x0ABEF</span>
strange_hex = <span class="hljs-number">0x1234_FACE_987D</span>
7 changes: 7 additions & 0 deletions test/markup/elixir/numbers.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
integer = 1234
integer_with_leading_zero = 01234
integer_zero = 0
big_integer = 1_234_000
neg_integer = -20_000
float = 2.34
float_with_leading_zero = 0.34
float_zero = 0.0
sci_float = 2.4e23
plus_sci_float = 2.4e+23
small_sci_float = 2.4e-23
cap_sci_float = 2.4E23
binary = 0b1010
binary_with_leading_zero = 0b0010
strange_binary = 0b1010_1010_1010
octal = 0o777
octal_with_leading_zero = 0o077
strange_octal = 0o777_666_555
hex = 0x1ABEF
hex_with_leading_zero = 0x0ABEF
strange_hex = 0x1234_FACE_987D

0 comments on commit 47f82c8

Please sign in to comment.