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

Unable to use custom Rouge formatter for highlighting #617

Closed
ashmaroli opened this issue Jul 10, 2019 · 7 comments
Closed

Unable to use custom Rouge formatter for highlighting #617

ashmaroli opened this issue Jul 10, 2019 · 7 comments
Assignees

Comments

@ashmaroli
Copy link
Contributor

Given that I have the following configuration:

syntax_highlighter_opts:
  formatter: HTMLTable

However when I try to convert a code-block, I get the following error:

private method `format' called for #<Hash:0x000000000601f440>

On bisecting, the issue occurs due to the following:

formatter = formatter_class(opts).new(opts)

The reason being that Rouge::Formatters::HTMLTable should be constructed by passing another "formatter" instance:

Rouge::Formatters::HTMLTable.new(Rouge::Formatters::HTML.new, opts)
@gettalong gettalong self-assigned this Aug 16, 2019
@gettalong
Copy link
Owner

It seems that the formatter subclasses don't share a common constructor interface. Some need the options, some another formatter, some yet another thing...

Any suggestions? The only way to solve this seems to be to specify the formatter as class and not as string.

@ashmaroli
Copy link
Contributor Author

I did take this issue up to Rouge's maintainers themselves, but there hasn't been a response till date.

Any suggestions?

I would recommend to implement an adapter of sorts. But not sure, if that lies within the scope of kramdown. So, left it as is..

@gettalong
Copy link
Owner

The problem with the adapter route is that if a formatter takes another formatter, which one should it take?

@ashmaroli
Copy link
Contributor Author

The basic idea is to emulate the implementation for Rouge::Formatters::HTMLLegacy
That class is unofficially deprecated for Rouge. They told me that it wouldn't get updated to handle newer formatters.

@daenney
Copy link

daenney commented Apr 5, 2020

I just ran into this issue trying to use HTMLLinewise from Jekyll. I'm curious if it's at all possible?

Any suggestions? The only way to solve this seems to be to specify the formatter as class and not as string.

This seems to suggest it should already be possible, or am I misunderstanding the comment?

@gettalong
Copy link
Owner

@daenney I really can't remember why I wrote what you quoted but since the formatter class is first resolved, regardless of whether it is specified as class or string, and only then an object instantiated, it won't be possible in this way.

Writing an adapter would work but I don't want to complicate things on kramdown's end when rouge can do that better.

So as @ashmaroli said: We are leaving this as it is for now and see what rouge does.

@gettalong
Copy link
Owner

@ashmaroli @daenney I don't think that rouge will do something about this. So on kramdown's end I will document the requirements for the formatter option of rouge and the user will need to make sure that s/he provides a correct (wrapper) class.

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

3 participants