diff --git a/lib/rouge/lexers/elixir.rb b/lib/rouge/lexers/elixir.rb index c48b65350b..07872ab160 100644 --- a/lib/rouge/lexers/elixir.rb +++ b/lib/rouge/lexers/elixir.rb @@ -103,7 +103,7 @@ def self.detect?(text) # Cribbed and adjusted from Ruby lexer delimiter_map = { '{' => '}', '[' => ']', '(' => ')', '<' => '>' } # Match a-z for custom sigils too - sigil_opens = Regexp.union(delimiter_map.keys + %w(| / ' ")) + sigil_opens = Regexp.union(delimiter_map.keys + [%r/"{3}/] + %w(| / ' ")) rule %r/~([A-Za-z])?(#{sigil_opens})/ do |m| open = Regexp.escape(m[2]) close = Regexp.escape(delimiter_map[m[2]] || m[2]) @@ -123,12 +123,18 @@ def self.detect?(text) push :list_flags end + if open == '"""' + toktype = Str::Doc + end + token toktype push do rule %r/#{close}/, toktype, :pop! - if interp + if toktype == Str::Doc + rule %r/(?:.|\n)*?"""/, toktype, :pop! + elsif interp mixin :interpoling rule %r/#/, toktype else diff --git a/spec/visual/samples/elixir b/spec/visual/samples/elixir index ac3bb253d1..3055989307 100644 --- a/spec/visual/samples/elixir +++ b/spec/visual/samples/elixir @@ -71,6 +71,21 @@ string |> String.split(~r/[ -]/) |> Enum.map(&abbreviate_word/1) |> Enum.join() ~S|inter #{pol <> "ati#{o}"} n| ~S/inter #{pol <> "ati#{o}"} n/ +# multiline sigil +~S""" +Converts double-quotes to single-quotes. + +## Examples + + iex> convert("\"foo\"") + "'foo'" +""" + +~H""" +Current temperature: <%= @temperature %>°F + +""" + # first is Operator, second is &1 variable &(&1)