jayferd/rouge — pull request #71 by sunaku (2013-04-09 17:53:13+00:00)
Title: [rouge-0.3.2] patch for viml lexer

Given the following Markdown input:

```vim
if &term =~ '256color'
" Disable Background Color Erase (BCE) so that color schemes
" work properly when Vim is used inside tmux and GNU screen.
" See also http://snk.tuxfamily.org/log/vim-256color-bce.html
set t_ut=
endif
```

Rouge::Plugins::Redcarpet encounters the following error:

```
no implicit conversion of nil into String
rouge-0.3.2/lib/rouge/lexers/viml.rb:67:in `start_with?'
rouge-0.3.2/lib/rouge/lexers/viml.rb:67:in `mapping_contains?'
rouge-0.3.2/lib/rouge/lexers/viml.rb:50:in `block (2 levels) in '
rouge-0.3.2/lib/rouge/regex_lexer.rb:235:in `instance_exec'
rouge-0.3.2/lib/rouge/regex_lexer.rb:235:in `block in run_callback'
rouge-0.3.2/lib/rouge/regex_lexer.rb:364:in `with_output_stream'
rouge-0.3.2/lib/rouge/regex_lexer.rb:232:in `run_callback'
rouge-0.3.2/lib/rouge/regex_lexer.rb:220:in `block in step'
rouge-0.3.2/lib/rouge/regex_lexer.rb:208:in `each'
rouge-0.3.2/lib/rouge/regex_lexer.rb:208:in `step'
rouge-0.3.2/lib/rouge/regex_lexer.rb:193:in `stream_tokens'
rouge-0.3.2/lib/rouge/lexer.rb:367:in `lex'
rouge-0.3.2/lib/rouge/formatters/html.rb:28:in `each'
rouge-0.3.2/lib/rouge/formatters/html.rb:28:in `stream_untableized'
rouge-0.3.2/lib/rouge/formatters/html.rb:22:in `stream'
rouge-0.3.2/lib/rouge/formatter.rb:31:in `format'
rouge-0.3.2/lib/rouge/plugins/redcarpet.rb:22:in `block_code'
```

The following patch fixes the problem for me:

```diff
--- rouge-0.3.2/lib/rouge/lexers/viml.rb.orig 2013-04-03 21:58:28.602197213 -0700
+++ rouge-0.3.2/lib/rouge/lexers/viml.rb 2013-04-03 21:58:36.431805036 -0700
@@ -63,7 +63,8 @@
def mapping_contains?(mapping, word)
shortest, longest = find_likely_mapping(mapping, word)

- word.start_with?(shortest) and longest.start_with?(word)
+ shortest and word.start_with?(shortest) and
+ longest and longest.start_with?(word)
end

# binary search through the mappings to find the one that's likely

```

Cheers! :smiley_cat: