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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,7 +1,7 @@
class ExtendedRougeSyntaxHighlighter < (Asciidoctor::SyntaxHighlighter.for 'rouge')
register_for 'rouge'

def create_formatter node, source, lang, opts
def create_html_formatter opts
formatter = super
formatter.singleton_class.prepend (Module.new do
def safe_span tok, safe_val
Expand Down
8 changes: 6 additions & 2 deletions lib/asciidoctor/syntax_highlighter/rouge.rb
Expand Up @@ -72,10 +72,14 @@ def create_lexer node, source, lang, opts
lexer || ::Rouge::Lexers::PlainText.new
end

def create_formatter node, source, lang, opts
formatter = opts[:css_mode] == :class ?
def create_html_formatter opts
opts[:css_mode] == :class ?
(::Rouge::Formatters::HTML.new inline_theme: @style) :
(::Rouge::Formatters::HTMLInline.new (::Rouge::Theme.find @style).new)
end

def create_formatter node, source, lang, opts
formatter = create_html_formatter opts
if (number_lines = opts[:number_lines])
formatter = RougeExt::Formatters::HTMLLineHighlighter.new formatter, lines: opts[:highlight_lines]
number_lines == :table ?
Expand Down