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

Rouge support will not accept custom formatter #214

Closed
IanTrudel opened this issue Feb 4, 2015 · 5 comments
Closed

Rouge support will not accept custom formatter #214

IanTrudel opened this issue Feb 4, 2015 · 5 comments

Comments

@IanTrudel
Copy link

@IanTrudel IanTrudel commented Feb 4, 2015

Syntax highlighting using Rouge has ::Rouge::Formatters::HTML.new(opts) formatter embedded into the code, not allowing the use of a custom formatter. It would be great to be able to pass a custom formatter as an option to the syntax highlighter.

CASE STUDY
I am using custom classes for Kramdown and Rouge to allow rendering in http://shoesrb.com/ to replace the old manual. Those classes generate methods that Shoes can interpret to create GUI elements according to the markdown.

For example, *This is in bold.* is transformed into para(strong("This is in bold.")). Rouge may determine it is a literal string and return, say, a color of value #336633, which would in turn be translated into para(strong("This is in bold."), :stroke => "#336633").

The current solution involves copying the code from Kramdown::Converter::SyntaxHighlighter::Rouge.call and replace the formatter with my custom formatter.

REFERENCE
https://github.com/gettalong/kramdown/blob/master/lib/kramdown/converter/syntax_highlighter/rouge.rb#L31

@gettalong gettalong self-assigned this Feb 4, 2015
@gettalong
Copy link
Owner

@gettalong gettalong commented Feb 4, 2015

So what you are saying is that you want a key like :formatter that can be passed to the syntax_highlighter_opts option and which is then used instead of the standard HTML formatter?

Something like:

formatter = (opts.delete(:formatter) || ::Rouge::Formatters::HTML).new(opts)
@IanTrudel
Copy link
Author

@IanTrudel IanTrudel commented Feb 4, 2015

Yes, exactly.

:syntax_highlighter_opts => { :formatter => Kramdown::Rouge::Formatters::MyCustomFormatter }
@gettalong
Copy link
Owner

@gettalong gettalong commented Feb 4, 2015

Okay, I think that can be done. Initially I had reservations because of possible code injections but specifying a constant is only doable by setting the option in Ruby and not via the {::options} extension, so that should be no problem.

@gettalong
Copy link
Owner

@gettalong gettalong commented Feb 5, 2015

Done!

@gettalong gettalong closed this Feb 5, 2015
gettalong added a commit that referenced this issue Feb 5, 2015
@IanTrudel
Copy link
Author

@IanTrudel IanTrudel commented Feb 5, 2015

Excellent, thanks! I am looking forward using this feature.

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

Successfully merging a pull request may close this issue.

None yet
2 participants