Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lexer options don't get passed to lexer #72

Open
alexanderweiss opened this issue Nov 29, 2017 · 2 comments
Open

Lexer options don't get passed to lexer #72

alexanderweiss opened this issue Nov 29, 2017 · 2 comments

Comments

@alexanderweiss
Copy link

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
@markets
Copy link
Member

markets commented Jan 19, 2024

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
Copy link
Member

markets commented Apr 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants