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

Expose unwrapped Rouge HTML formatter #4472

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Commits on Jul 22, 2023

  1. Expose unwrapped Rouge HTML formatter

    This exposes the Rouge HTML formatter prior to any extension wrapping in order to allow further customizations when overriding the `Asciidoctor::SyntaxHighlighter::RougeAdapter` class.
    
    Prior to these changes, executing for example this code:
    
    ```ruby
    class ExtendedRougeSyntaxHighlighter < (Asciidoctor::SyntaxHighlighter.for 'rouge')
      register_for 'rouge'
    
      def create_formatter node, source, lang, opts
        formatter = super
        formatter.singleton_class.prepend (Module.new do
          def safe_span tok, safe_val
            if tok.token_chain[0].matches? ::Rouge::Token::Tokens::Comment
              safe_val = safe_val.gsub(/https?:\/\/\S+/, '<a href="\&">\&</a>')
            end
            super
          end
        end)
        formatter
      end
    end
    ```
    
    Could potentially cause to override classes that do not implement `safe_span()`, for example `RougeExt::Formatters::HTMLTableLineNumberer` as we expect `Rouge::Formatters::HTML` instead.
    
    Those other classes (`RougeExt::Formatters::*`) may be useful for extensions to keep enabled but currently need to be disabled as they are shadowing `Rouge::Formatters::HTML`.
    NyanKiyoshi committed Jul 22, 2023
    Configuration menu
    Copy the full SHA
    c630463 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    e8379b5 View commit details
    Browse the repository at this point in the history