Skip to content

Commit

Permalink
Elixir: Make regexps greedy, remove comment hacks. Update known failu…
Browse files Browse the repository at this point in the history
…res and tests.
  • Loading branch information
Golmote committed Mar 26, 2018
1 parent c083b78 commit e93d61f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
10 changes: 5 additions & 5 deletions components/prism-elixir.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Prism.languages.elixir = {
// Negative look-ahead is needed for string interpolation
// Negative look-behind is needed to avoid highlighting markdown headers in
// multi-line doc strings
'comment': {
pattern: /(^|[^#])#(?![{#]).*/m,
pattern: /#.*/m,
lookbehind: true
},
// ~r"""foo""" (multi-line), ~r'''foo''' (multi-line), ~r/foo/, ~r|foo|, ~r"foo", ~r'foo', ~r(foo), ~r[foo], ~r{foo}, ~r<foo>
'regex': /~[rR](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([\/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|[^\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[uismxfr]*/,
'regex': {
pattern: /~[rR](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([\/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|[^\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[uismxfr]*/,
greedy: true
},
'string': [
{
// ~s"""foo""" (multi-line), ~s'''foo''' (multi-line), ~s/foo/, ~s|foo|, ~s"foo", ~s'foo', ~s(foo), ~s[foo], ~s{foo} (with interpolation care), ~s<foo>
Expand Down
2 changes: 1 addition & 1 deletion components/prism-elixir.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions examples/prism-elixir.html
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,5 @@ <h2>Known failures</h2>
If a failure is listed here, it doesn’t mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug.
</p>

<h3>Comments starting with an opening curly brace</h3>
<pre><code>#{ This is not highlighted properly.</code></pre>

<h3>String interpolation in single-quoted strings</h3>
<pre><code>'#{:atom} &lt;- this should not be highligted'</code></pre>

<pre><code>'#{:atom} &lt;- this should not be highligted'</code></pre>
4 changes: 3 additions & 1 deletion tests/languages/elixir/comment_feature.test
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#
# Foobar
#{ This is a comment

----------------------------------------------------

[
["comment", "#"],
["comment", "# Foobar"]
["comment", "# Foobar"],
["comment", "#{ This is a comment"]
]

----------------------------------------------------
Expand Down

0 comments on commit e93d61f

Please sign in to comment.