middleman-syntax icon indicating copy to clipboard operation
middleman-syntax copied to clipboard

Lexer options don't get passed to lexer

Open alexanderweiss opened this issue 6 years ago â€ĸ 2 comments

Lexer options, defined in config.rb don't seem to get passed to passed to the lexer:

activate :syntax, lexer_options: { prompt: '$,#,;' }

The above doesn't actually override the default settings of the console lexer.

I've been trying to figure out what was going on and it seems like the lexer_options need to be passed as the third argument to find_fancy, rather than to lexer.lex (in https://github.com/middleman/middleman-syntax/blob/master/lib/middleman-syntax/highlighter.rb):

def self.highlight(code, language=nil, opts={})
  highlighter_options = options.to_h.merge(opts)
  formatter = Middleman::Syntax::Formatters::HTML.new(highlighter_options)
  lexer_options = highlighter_options.delete(:lexer_options)
  
  lexer = Rouge::Lexer.find_fancy(language, code, lexer_options) || Rouge::Lexers::PlainText
  
  highlighter_options[:css_class] = [ highlighter_options[:css_class], lexer.tag ].join(' ')
  
  formatter.format(lexer.lex(code, lexer_options))
end

alexanderweiss avatar Nov 29 '17 16:11 alexanderweiss

Hey @alexanderweiss 👋đŸŧ

Would you like to send a patch? Better late than never đŸ’ĒđŸŧ.

I think it makes sense what you mentioned in the comment above ☝đŸŧ.

markets avatar Jan 19 '24 17:01 markets

Hello @alexanderweiss 👋đŸŧ

Sorry for the ping! Just wanted to ask if you can help us to fix this one 🙏đŸŧ If you can send a patch, that would be amazing, otherwise if you can point me to the right docs I'll try to submit a patch (and a test) by myself. Would like to better understand what this lexer_options: { prompt: '$,#,;' } is supposed to do, I've never used raw Rouge and I'm not familiar with some concepts as the lexer.

ℹī¸ I started some months ago to collaborate in the Middleman ecosystem, so I'm trying to catch up with old issues/PRs.

markets avatar Apr 15 '24 18:04 markets