Skip to content

fix(ex) #4238 and add test #4241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 23, 2025
Merged
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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Core Grammars:
- fix(javascript) correctly highlight 'for await' again [wolfgang42][]
- enh(csp) add missing directives / keywords from MDN (7 more) [Max Liashuk][]
- enh(ada) add new `parallel` keyword, allow `[]` for Ada 2022 [Max Reznik][]
- fix(ex) adds support for `?'` char literal and missing `defguardp` keyword [Kevin Bloch][]
- fix(diff) fix unified diff hunk header regex to allow unpaired numbers [Chris Wilson][]
- enh(php) support single line and hash comments in attributes, constructor and functions [Antoine Musso][]

Expand All @@ -18,6 +19,7 @@ CONTRIBUTORS
[Josh Marchand]: https://github.com/yHSJ
[Max Liashuk]: https://github.com/probil
[Max Reznik]: https://github.com/reznikmm
[Kevin Bloch]: https://github.com/codingthat
[Chris Wilson]: https://github.com/sushicw
[Antoine Musso]: https://github.com/hashar
[Chester Moses]: https://github.com/Chester-Moses-HCL
Expand Down
7 changes: 7 additions & 0 deletions src/languages/elixir.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function(hljs) {
"cond",
"defstruct",
"defguard",
"defguardp",
"do",
"else",
"end",
Expand Down Expand Up @@ -228,7 +229,13 @@ export default function(hljs) {
beginKeywords: 'defimpl defmodule defprotocol defrecord',
end: /\bdo\b|$|;/
});
const CHAR_LITERAL = {
scope: 'string',
match: /\?'/,
relevance: 0
};
const ELIXIR_DEFAULT_CONTAINS = [
CHAR_LITERAL,
STRING,
REGEX_SIGIL,
UPCASE_SIGIL,
Expand Down
1 change: 1 addition & 0 deletions test/detect/elixir/default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ guy = Person.new first_name: "Guy"
guy.name

defmodule ListServer do
defguardp apostrophe?(c) when c == ?'
@moduledoc """
This module provides an easy to use ListServer, useful for keeping
lists of things.
Expand Down
2 changes: 2 additions & 0 deletions test/markup/elixir/char-literal.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<span class="hljs-keyword">defguardp</span> apostrophe?(c) <span class="hljs-keyword">when</span> c == <span class="hljs-string">?&#x27;</span>
<span class="hljs-keyword">defguardp</span> upper?(c) <span class="hljs-keyword">when</span> (c &gt;= ?A <span class="hljs-keyword">and</span> c &lt;= ?Z)
2 changes: 2 additions & 0 deletions test/markup/elixir/char-literal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
defguardp apostrophe?(c) when c == ?'
defguardp upper?(c) when (c >= ?A and c <= ?Z)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are ?A and ?Z then? Are they not also char literals?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are, but char literals can be any character. To keep the change small and the matching efficient, I just targeted the most problematic case (at least for now). If you want to leave them absolutely consistent with other char literals, disabling highlighting ?' (I guess with className: null?) could also work.