Skip to content

Unable to use custom Rouge formatter for highlighting #617

Closed

Description

@ashmaroli

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)

Activity

  1. self-assigned this
    on Aug 16, 2019
  2. gettalong commented on Aug 16, 2019

    @gettalong
    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.

  3. ashmaroli commented on Aug 16, 2019

    @ashmaroli
    ContributorAuthor

    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..

  4. gettalong commented on Aug 16, 2019

    @gettalong
    Owner

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

  5. ashmaroli commented on Aug 16, 2019

    @ashmaroli
    ContributorAuthor

    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.

  6. daenney commented on Apr 5, 2020

    @daenney

    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?

  7. gettalong commented on Apr 16, 2020

    @gettalong
    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.

  8. gettalong commented on Jan 6, 2021

    @gettalong
    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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions