Skip to content

Commit

Permalink
Highlight Elixir string markdown header correctly
Browse files Browse the repository at this point in the history
Elixir allows markdown inside its triple-quote heredoc syntax. However,
the "#" used in markdown headers is currently misinterpreted as a
comment. So, if you write this:

```elixir
@doc """
Get the first name of a user.

- `user` - A User struct.

    user = %User{name: "Alice Winston"}
    User.first_name(user)
    "Alice"

"""
```

Prism interprets the markdown headers as comments, not as part of the
string, and this messes up the coloring.

This can be fixed by adding a negative lookbehind, such that the
comments regex matches "#" but not "##".
  • Loading branch information
danielberkompas committed Sep 22, 2015
1 parent b2763e7 commit 1aede3e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions components/prism-elixir.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Prism.languages.elixir = {
// Negative look-ahead is needed for string interpolation
'comment': /#(?!\{).*/,
// Negated capture group is needed to avoid highlighting markdown headers in
// multi-line doc strings
'comment': {
pattern: /([^#])#(?![{#]).*/,
lookbehind: true
},
// ~r"""foo""", ~r'''foo''', ~r/foo/, ~r|foo|, ~r"foo", ~r'foo', ~r(foo), ~r[foo], ~r{foo}, ~r<foo>
'regex': /~[rR](?:("""|'''|[\/|"'])(?:\\.|(?!\1)[^\\])+\1|\((?:\\\)|[^)])+\)|\[(?:\\\]|[^\]])+\]|\{(?:\\\}|[^}])+\}|<(?:\\>|[^>])+>)[uismxfr]*/,
'string': [
Expand Down Expand Up @@ -81,4 +86,5 @@ Prism.languages.elixir.string.forEach(function(o) {
}
}
};
});
});

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.

0 comments on commit 1aede3e

Please sign in to comment.