Skip to content

Commit e150dba

Browse files
Copilotmarkets
andauthored
Lexer options don't get passed to lexer (#92)
Co-authored-by: Marc Anguera Insa <[email protected]>
1 parent 97ca940 commit e150dba

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
coverage
33
rdoc
44
pkg
5-
.sass-cache
6-
.sassc
75
.tmp
86
Gemfile.lock
97
docs
10-
.rbenv-*
118
.*.swp
129
build
1310
doc
1411
.yardoc
1512
tmp
1613
Makefile
17-
.mm-pid-*
14+
.bundle
15+
vendor/bundle

features/lexer_options.feature

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Feature: Lexer options configuration
2+
3+
Scenario: Lexer options are passed to Rouge lexer
4+
Given a fixture app "test-app"
5+
And a file named "config.rb" with:
6+
"""
7+
activate :syntax, :lexer_options => { :prompt => 'myshell>>>' }
8+
"""
9+
And a file named "source/console_code.html.erb" with:
10+
"""
11+
<% code("console") do %>
12+
myshell>>> echo "hello world"
13+
myshell>>> echo "test"
14+
<% end %>
15+
"""
16+
And the Server is running
17+
When I go to "/console_code.html"
18+
Then I should see '<span class="gp">myshell&gt;&gt;&gt;</span>'
19+
And I should not see '<span class="o">&gt;&gt;</span>'

features/support/step_definitions.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,13 @@
22
Then(/^I should not see line numbers markup$/) do
33
expect(page).not_to have_selector("pre.lineno")
44
end
5+
6+
# step definition for testing that specific content is not present
7+
Then(/^I should not see "([^"]*)"$/) do |content|
8+
expect(page.body).not_to include(content)
9+
end
10+
11+
# step definition for testing that specific content is not present (new format)
12+
Then('I should not see {string}') do |content|
13+
expect(page.body).not_to include(content)
14+
end

lib/middleman-syntax/highlighter.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ module Highlighter
77

88
# A helper module for highlighting code
99
def self.highlight(code, language=nil, opts={})
10-
lexer = Rouge::Lexer.find_fancy(language, code) || Rouge::Lexers::PlainText
11-
1210
highlighter_options = options.to_h.merge(opts)
13-
highlighter_options[:css_class] = [ highlighter_options[:css_class], lexer.tag ].join(' ')
1411
lexer_options = highlighter_options.delete(:lexer_options)
12+
13+
lexer = Rouge::Lexer.find_fancy(language, code, lexer_options) || Rouge::Lexers::PlainText
14+
15+
highlighter_options[:css_class] = [ highlighter_options[:css_class], lexer.tag ].join(' ')
1516

1617
formatter = Middleman::Syntax::Formatters::HTML.new(highlighter_options)
17-
formatter.format(lexer.lex(code, lexer_options))
18+
formatter.format(lexer.lex(code))
1819
end
1920
end
2021
end

0 commit comments

Comments
 (0)