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

Restrict Rouge formatters to Rouge::Formatters namespace #708

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/kramdown/converter/syntax_highlighter/rouge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def self.formatter_class(opts = {})
when Class
formatter
when /\A[[:upper:]][[:alnum:]_]*\z/
::Rouge::Formatters.const_get(formatter)
::Rouge::Formatters.const_get(formatter, false)
else
# Available in Rouge 2.0 or later
::Rouge::Formatters::HTMLLegacy
Expand Down
18 changes: 11 additions & 7 deletions test/test_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@
end

# custom formatter for tests
class RougeHTMLFormatters < Kramdown::Converter::SyntaxHighlighter::Rouge.formatter_class
module Rouge
module Formatters
class RougeHTMLFormatters < Kramdown::Converter::SyntaxHighlighter::Rouge.formatter_class

tag 'rouge_html_formatters'
tag 'rouge_html_formatters'

def stream(tokens, &b)
yield %(<div class="custom-class">)
super
yield %(</div>)
end
def stream(tokens, &b)
yield %(<div class="custom-class">)
super
yield %(</div>)
end

end
end
end
rescue LoadError, SyntaxError, NameError
end
Expand Down