rouge-ruby / rouge

A pure Ruby code highlighter that is compatible with Pygments

Home Page:https://rouge.jneen.net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lacking documentation: How to make a Rouge Lexer in a non-Rouge gem?

dhendriks opened this issue · comments

I found https://rouge-ruby.github.io/docs/file.LexerDevelopment.html with instructions on how to make a Rouge Lexer, and contribute it to Rouge. I was able to use the instructions quite easily to make a custom Lexer. However, what I can't find is how to distribute the Lexer in a separate gem, and have Rouge work with that (thus, be able to find and load it). How would one go about that?

What I found is that Rouge loads lexers using a hardcoded relative path, namely rouge/lexers. I did not find any code that makes it look elsewhere.

Since you're probably going to ask why I want this: If I update the language I'm developing, and for instance add a new keyword, I want to be able to include the new syntax in my project's documentation. This means I need a new version of the lexer to highlight for instance the new keyword. But, if the lexer is part of Rouge itself, I need a new version of Rouge, before I can do a release of my project. Therefore, it would be good if I could include my own lexer in my own project, to not be dependent on new Rouge releases. This doesn't mean I shouldn't also contribute it to Rouge itself, but I'd like to be able to also have it as part of my own project.